- {
- “cells”: [
- {
“cell_type”: “markdown”, “metadata”: {
- “slideshow”: {
“slide_type”: “slide”
}
}, “source”: [
“n”, “n”, “<font size = "5"> Chapter 2: [Diffraction](CH2_00-Diffraction.ipynb) </font>n”, “n”, “<hr style="height:1px;border-top:4px solid #FF8200" />n”, “n”, “# Analyzing Ring Diffraction Patternn”, “[Download](https://raw.githubusercontent.com/gduscher/MSE672-Introduction-to-TEM//main/Diffraction/CH2_03-Basic_Crystallography.ipynb)n”, ” n”, “[](n”, ” https://colab.research.google.com/github/gduscher/MSE672-Introduction-to-TEM/blob/main/Diffraction/CH2_03-Basic_Crystallography.ipynb)n”, “n”, “n”, “n”, “part of n”, “n”, “<font size = "5"> **[MSE672: Introduction to Transmission Electron Microscopy](../_MSE672_Intro_TEM.ipynb)**</font>n”, “n”, “by Gerd Duscher, Spring 2021n”, “n”, “Microscopy Facilities<br>n”, “Joint Institute of Advanced Materials<br>n”, “Materials Science & Engineering<br>n”, “The University of Tennessee, Knoxvillen”, “n”, “Background and methods to analysis and quantification of data acquired with transmission electron microscopes.”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Load relevant python packagesn”, “### Check Installed Packages”
]
}, {
“cell_type”: “code”, “execution_count”: 1, “metadata”: {}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“donen”
]
}
], “source”: [
“import sysn”, “from pkg_resources import get_distribution, DistributionNotFoundn”, “n”, “def test_package(package_name):n”, ” """Test if package exists and returns version or -1"""n”, ” try:n”, ” version = get_distribution(package_name).versionn”, ” except (DistributionNotFound, ImportError) as err:n”, ” version = ‘-1’n”, ” return versionn”, “n”, “# Colab setup ——————n”, “if ‘google.colab’ in sys.modules:n”, ” !pip install pyTEMlib -qn”, “# pyTEMlib setup ——————n”, “else:n”, ” if test_package(‘pyTEMlib’) < ‘0.2021.1.9’:n”, ” print(‘installing pyTEMlib’)n”, ” !{sys.executable} -m pip install –upgrade pyTEMlib -qn”, “# ——————————n”, “print(‘done’)”
]
}, {
“cell_type”: “markdown”, “metadata”: {
- “slideshow”: {
“slide_type”: “slide”
}
}, “source”: [
“### Load the plotting and figure packagesn”, “Import the python packages that we will use:n”, “n”, “Beside the basic numerical (numpy) and plotting (pylab of matplotlib) libraries,n”, “* three dimensional plottingn”, “and some libraries from the bookn”, “* kinematic scattering library.”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 1,
- “metadata”: {
- “slideshow”: {
“slide_type”: “-“
}
}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“Populating the interactive namespace from numpy and matplotlibn”, “Using KinsCat library version 0.5 by G.Duschern”, “spglib not installed; Symmetry functions of spglib disabledn”,
- <<<<<<< HEAD
“pyTEM version: 0.2021.02.09n”, “pyTEM version: 0.2021.02.09n”,
- >>>>>>> d27eb02fc99b5249297c72b2b388a2377fbe501e
“notebook version: 2021.02.03n”
]
}
], “source”: [
“import sysn”, “if ‘google.colab’ in sys.modules:n”, ” %pylab –no-import-all inlinen”, “else:n”, ” %pylab –no-import-all notebookn”, ” %gui qtn”, “n”, “# additional package n”, “import itertools n”, “import scipy.constants as constn”, “import ipywidgets as ipywn”, “n”, “# Import libraries from the bookn”, “import pyTEMlibn”, “import pyTEMlib.KinsCat as ks # Kinematic sCattering Libraryn”, ” # Atomic form factors from Kirklands bookn”, “n”, “### And we use the file tool library of pyTEMlib to open filesn”, “import pyTEMlib.file_tools as ftn”, “n”, “print(‘pyTEM version: ‘,pyTEMlib.__version__)n”, “n”, “__notebook__=’MSE672-CH2_05-Diffraction_Rings’n”, “__notebook_version__=’2021-02-03’n”, “__notebook_version__ = ‘2021.02.03’n”, “print(‘pyTEM version: ‘, pyTEMlib.__version__)n”, “print(‘notebook version: ‘, __notebook_version__)”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Load Ring-Diffraction Patternn”, “### First we select the diffraction patternn”, “n”, “Load the GOLD-NP-DIFF.dm3 file as an example.n”, “n”, “The dynamic range of diffraction patterns is too high for computer screens and so we take the logarithm of the intensity. “
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 2, “metadata”: {}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“Cannot overwrite file. Using: GOLD_NP_DIFF-7.hf5n”
]
}, {
“name”: “stderr”, “output_type”: “stream”, “text”: [
“C:\Users\gduscher\Anaconda3\lib\site-packages\pyNSID\io\hdf_utils.py:351: FutureWarning: validate_h5_dimension may be removed in a future versionn”,
- “outputs”: [
- {
“name”: “stderr”, “output_type”: “stream”, “text”: [
“C:\Users\nosle\anaconda3\lib\site-packages\pyNSID\io\hdf_utils.py:351: FutureWarning: validate_h5_dimension may be removed in a future versionn”,
- >>>>>>> d27eb02fc99b5249297c72b2b388a2377fbe501e
” warn(‘validate_h5_dimension may be removed in a future version’,n”
]
}, {
- “data”: {
- “application/javascript”: [
“/* Put everything inside the global mpl namespace /n”, “/ global mpl */n”, “window.mpl = {};n”, “n”, “mpl.get_websocket_type = function () {n”, ” if (typeof WebSocket !== ‘undefined’) {n”, ” return WebSocket;n”, ” } else if (typeof MozWebSocket !== ‘undefined’) {n”, ” return MozWebSocket;n”, ” } else {n”, ” alert(n”, ” ‘Your browser does not have WebSocket support. ‘ +n”, ” ‘Please try Chrome, Safari or Firefox ≥ 6. ‘ +n”, ” ‘Firefox 4 and 5 are also supported but you ‘ +n”, ” ‘have to enable WebSockets in about:config.’n”, ” );n”, ” }n”, “};n”, “n”, “mpl.figure = function (figure_id, websocket, ondownload, parent_element) {n”, ” this.id = figure_id;n”, “n”, ” this.ws = websocket;n”, “n”, ” this.supports_binary = this.ws.binaryType !== undefined;n”, “n”, ” if (!this.supports_binary) {n”, ” var warnings = document.getElementById(‘mpl-warnings’);n”, ” if (warnings) {n”, ” warnings.style.display = ‘block’;n”, ” warnings.textContent =n”, ” ‘This browser does not support binary websocket messages. ‘ +n”, ” ‘Performance may be slow.’;n”, ” }n”, ” }n”, “n”, ” this.imageObj = new Image();n”, “n”, ” this.context = undefined;n”, ” this.message = undefined;n”, ” this.canvas = undefined;n”, ” this.rubberband_canvas = undefined;n”, ” this.rubberband_context = undefined;n”, ” this.format_dropdown = undefined;n”, “n”, ” this.image_mode = ‘full’;n”, “n”, ” this.root = document.createElement(‘div’);n”, ” this.root.setAttribute(‘style’, ‘display: inline-block’);n”, ” this._root_extra_style(this.root);n”, “n”, ” parent_element.appendChild(this.root);n”, “n”, ” this._init_header(this);n”, ” this._init_canvas(this);n”, ” this._init_toolbar(this);n”, “n”, ” var fig = this;n”, “n”, ” this.waiting = false;n”, “n”, ” this.ws.onopen = function () {n”, ” fig.send_message(‘supports_binary’, { value: fig.supports_binary });n”, ” fig.send_message(‘send_image_mode’, {});n”, ” if (fig.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: fig.ratio });n”, ” }n”, ” fig.send_message(‘refresh’, {});n”, ” };n”, “n”, ” this.imageObj.onload = function () {n”, ” if (fig.image_mode === ‘full’) {n”, ” // Full images could contain transparency (where diff imagesn”, ” // almost always do), so we need to clear the canvas so thatn”, ” // there is no ghosting.n”, ” fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);n”, ” }n”, ” fig.context.drawImage(fig.imageObj, 0, 0);n”, ” };n”, “n”, ” this.imageObj.onunload = function () {n”, ” fig.ws.close();n”, ” };n”, “n”, ” this.ws.onmessage = this._make_on_message_function(this);n”, “n”, ” this.ondownload = ondownload;n”, “};n”, “n”, “mpl.figure.prototype._init_header = function () {n”, ” var titlebar = document.createElement(‘div’);n”, ” titlebar.classList =n”, ” ‘ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix’;n”, ” var titletext = document.createElement(‘div’);n”, ” titletext.classList = ‘ui-dialog-title’;n”, ” titletext.setAttribute(n”, ” ‘style’,n”, ” ‘width: 100%; text-align: center; padding: 3px;’n”, ” );n”, ” titlebar.appendChild(titletext);n”, ” this.root.appendChild(titlebar);n”, ” this.header = titletext;n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._root_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._init_canvas = function () {n”, ” var fig = this;n”, “n”, ” var canvas_div = (this.canvas_div = document.createElement(‘div’));n”, ” canvas_div.setAttribute(n”, ” ‘style’,n”, ” ‘border: 1px solid #ddd;’ +n”, ” ‘box-sizing: content-box;’ +n”, ” ‘clear: both;’ +n”, ” ‘min-height: 1px;’ +n”, ” ‘min-width: 1px;’ +n”, ” ‘outline: 0;’ +n”, ” ‘overflow: hidden;’ +n”, ” ‘position: relative;’ +n”, ” ‘resize: both;’n”, ” );n”, “n”, ” function on_keyboard_event_closure(name) {n”, ” return function (event) {n”, ” return fig.key_event(event, name);n”, ” };n”, ” }n”, “n”, ” canvas_div.addEventListener(n”, ” ‘keydown’,n”, ” on_keyboard_event_closure(‘key_press’)n”, ” );n”, ” canvas_div.addEventListener(n”, ” ‘keyup’,n”, ” on_keyboard_event_closure(‘key_release’)n”, ” );n”, “n”, ” this._canvas_extra_style(canvas_div);n”, ” this.root.appendChild(canvas_div);n”, “n”, ” var canvas = (this.canvas = document.createElement(‘canvas’));n”, ” canvas.classList.add(‘mpl-canvas’);n”, ” canvas.setAttribute(‘style’, ‘box-sizing: content-box;’);n”, “n”, ” this.context = canvas.getContext(‘2d’);n”, “n”, ” var backingStore =n”, ” this.context.backingStorePixelRatio ||n”, ” this.context.webkitBackingStorePixelRatio ||n”, ” this.context.mozBackingStorePixelRatio ||n”, ” this.context.msBackingStorePixelRatio ||n”, ” this.context.oBackingStorePixelRatio ||n”, ” this.context.backingStorePixelRatio ||n”, ” 1;n”, “n”, ” this.ratio = (window.devicePixelRatio || 1) / backingStore;n”, ” if (this.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: this.ratio });n”, ” }n”, “n”, ” var rubberband_canvas = (this.rubberband_canvas = document.createElement(n”, ” ‘canvas’n”, ” ));n”, ” rubberband_canvas.setAttribute(n”, ” ‘style’,n”, ” ‘box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;’n”, ” );n”, “n”,
- <<<<<<< HEAD
” // Apply a ponyfill if ResizeObserver is not implemented by browser.n”, ” if (this.ResizeObserver === undefined) {n”, ” if (window.ResizeObserver !== undefined) {n”, ” this.ResizeObserver = window.ResizeObserver;n”, ” } else {n”, ” var obs = _JSXTOOLS_RESIZE_OBSERVER({});n”, ” this.ResizeObserver = obs.ResizeObserver;n”, ” }n”, ” }n”, “n”, ” this.resizeObserverInstance = new this.ResizeObserver(function (entries) {n”,
” var nentries = entries.length;n”, ” for (var i = 0; i < nentries; i++) {n”, ” var entry = entries[i];n”, ” var width, height;n”, ” if (entry.contentBoxSize) {n”, ” if (entry.contentBoxSize instanceof Array) {n”, ” // Chrome 84 implements new version of spec.n”, ” width = entry.contentBoxSize[0].inlineSize;n”, ” height = entry.contentBoxSize[0].blockSize;n”, ” } else {n”, ” // Firefox implements old version of spec.n”, ” width = entry.contentBoxSize.inlineSize;n”, ” height = entry.contentBoxSize.blockSize;n”, ” }n”, ” } else {n”, ” // Chrome <84 implements even older version of spec.n”, ” width = entry.contentRect.width;n”, ” height = entry.contentRect.height;n”, ” }n”, “n”, ” // Keep the size of the canvas and rubber band canvas in sync withn”, ” // the canvas container.n”, ” if (entry.devicePixelContentBoxSize) {n”, ” // Chrome 84 implements new version of spec.n”, ” canvas.setAttribute(n”, ” ‘width’,n”, ” entry.devicePixelContentBoxSize[0].inlineSizen”, ” );n”, ” canvas.setAttribute(n”, ” ‘height’,n”, ” entry.devicePixelContentBoxSize[0].blockSizen”, ” );n”, ” } else {n”, ” canvas.setAttribute(‘width’, width * fig.ratio);n”, ” canvas.setAttribute(‘height’, height * fig.ratio);n”, ” }n”, ” canvas.setAttribute(n”, ” ‘style’,n”, ” ‘width: ‘ + width + ‘px; height: ‘ + height + ‘px;’n”, ” );n”, “n”, ” rubberband_canvas.setAttribute(‘width’, width);n”, ” rubberband_canvas.setAttribute(‘height’, height);n”, “n”, ” // And update the size in Python. We ignore the initial 0/0 sizen”, ” // that occurs as the element is placed into the DOM, which shouldn”, ” // otherwise not happen due to the minimum size styling.n”, ” if (width != 0 && height != 0) {n”, ” fig.request_resize(width, height);n”, ” }n”, ” }n”, ” });n”,
- <<<<<<< HEAD
” this.resizeObserverInstance.observe(canvas_div);n”,
“n”, ” function on_mouse_event_closure(name) {n”, ” return function (event) {n”, ” return fig.mouse_event(event, name);n”, ” };n”, ” }n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousedown’,n”, ” on_mouse_event_closure(‘button_press’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseup’,n”, ” on_mouse_event_closure(‘button_release’)n”, ” );n”, ” // Throttle sequential mouse events to 1 every 20ms.n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousemove’,n”, ” on_mouse_event_closure(‘motion_notify’)n”, ” );n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseenter’,n”, ” on_mouse_event_closure(‘figure_enter’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseleave’,n”, ” on_mouse_event_closure(‘figure_leave’)n”, ” );n”, “n”, ” canvas_div.addEventListener(‘wheel’, function (event) {n”, ” if (event.deltaY < 0) {n”, ” event.step = 1;n”, ” } else {n”, ” event.step = -1;n”, ” }n”, ” on_mouse_event_closure(‘scroll’)(event);n”, ” });n”, “n”, ” canvas_div.appendChild(canvas);n”, ” canvas_div.appendChild(rubberband_canvas);n”, “n”, ” this.rubberband_context = rubberband_canvas.getContext(‘2d’);n”, ” this.rubberband_context.strokeStyle = ‘#000000’;n”, “n”, ” this._resize_canvas = function (width, height, forward) {n”, ” if (forward) {n”, ” canvas_div.style.width = width + ‘px’;n”, ” canvas_div.style.height = height + ‘px’;n”, ” }n”, ” };n”, “n”, ” // Disable right mouse context menu.n”, ” this.rubberband_canvas.addEventListener(‘contextmenu’, function (_e) {n”, ” event.preventDefault();n”, ” return false;n”, ” });n”, “n”, ” function set_focus() {n”, ” canvas.focus();n”, ” canvas_div.focus();n”, ” }n”, “n”, ” window.setTimeout(set_focus, 100);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘mpl-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. /n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” continue;n”, ” }n”, “n”, ” var button = (fig.buttons[name] = document.createElement(‘button’));n”, ” button.classList = ‘mpl-widget’;n”, ” button.setAttribute(‘role’, ‘button’);n”, ” button.setAttribute(‘aria-disabled’, ‘false’);n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, “n”, ” var icon_img = document.createElement(‘img’);n”, ” icon_img.src = ‘_images/’ + image + ‘.png’;n”, ” icon_img.srcset = ‘_images/’ + image + ‘_large.png 2x’;n”, ” icon_img.alt = tooltip;n”, ” button.appendChild(icon_img);n”, “n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” var fmt_picker = document.createElement(‘select’);n”, ” fmt_picker.classList = ‘mpl-widget’;n”, ” toolbar.appendChild(fmt_picker);n”, ” this.format_dropdown = fmt_picker;n”, “n”, ” for (var ind in mpl.extensions) {n”, ” var fmt = mpl.extensions[ind];n”, ” var option = document.createElement(‘option’);n”, ” option.selected = fmt === mpl.default_extension;n”, ” option.innerHTML = fmt;n”, ” fmt_picker.appendChild(option);n”, ” }n”, “n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “};n”, “n”, “mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {n”, ” // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,n”, ” // which will in turn request a refresh of the image.n”, ” this.send_message(‘resize’, { width: x_pixels, height: y_pixels });n”, “};n”, “n”, “mpl.figure.prototype.send_message = function (type, properties) {n”, ” properties[‘type’] = type;n”, ” properties[‘figure_id’] = this.id;n”, ” this.ws.send(JSON.stringify(properties));n”, “};n”, “n”, “mpl.figure.prototype.send_draw_message = function () {n”, ” if (!this.waiting) {n”, ” this.waiting = true;n”, ” this.ws.send(JSON.stringify({ type: ‘draw’, figure_id: this.id }));n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” var format_dropdown = fig.format_dropdown;n”, ” var format = format_dropdown.options[format_dropdown.selectedIndex].value;n”, ” fig.ondownload(fig, format);n”, “};n”, “n”, “mpl.figure.prototype.handle_resize = function (fig, msg) {n”, ” var size = msg[‘size’];n”, ” if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {n”, ” fig._resize_canvas(size[0], size[1], msg[‘forward’]);n”, ” fig.send_message(‘refresh’, {});n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_rubberband = function (fig, msg) {n”, ” var x0 = msg[‘x0’] / fig.ratio;n”, ” var y0 = (fig.canvas.height - msg[‘y0’]) / fig.ratio;n”, ” var x1 = msg[‘x1’] / fig.ratio;n”, ” var y1 = (fig.canvas.height - msg[‘y1’]) / fig.ratio;n”, ” x0 = Math.floor(x0) + 0.5;n”, ” y0 = Math.floor(y0) + 0.5;n”, ” x1 = Math.floor(x1) + 0.5;n”, ” y1 = Math.floor(y1) + 0.5;n”, ” var min_x = Math.min(x0, x1);n”, ” var min_y = Math.min(y0, y1);n”, ” var width = Math.abs(x1 - x0);n”, ” var height = Math.abs(y1 - y0);n”, “n”, ” fig.rubberband_context.clearRect(n”, ” 0,n”, ” 0,n”, ” fig.canvas.width / fig.ratio,n”, ” fig.canvas.height / fig.ration”, ” );n”, “n”, ” fig.rubberband_context.strokeRect(min_x, min_y, width, height);n”, “};n”, “n”, “mpl.figure.prototype.handle_figure_label = function (fig, msg) {n”, ” // Updates the figure title.n”, ” fig.header.textContent = msg[‘label’];n”, “};n”, “n”, “mpl.figure.prototype.handle_cursor = function (fig, msg) {n”, ” var cursor = msg[‘cursor’];n”, ” switch (cursor) {n”, ” case 0:n”, ” cursor = ‘pointer’;n”, ” break;n”, ” case 1:n”, ” cursor = ‘default’;n”, ” break;n”, ” case 2:n”, ” cursor = ‘crosshair’;n”, ” break;n”, ” case 3:n”, ” cursor = ‘move’;n”, ” break;n”, ” }n”, ” fig.rubberband_canvas.style.cursor = cursor;n”, “};n”, “n”, “mpl.figure.prototype.handle_message = function (fig, msg) {n”, ” fig.message.textContent = msg[‘message’];n”, “};n”, “n”, “mpl.figure.prototype.handle_draw = function (fig, _msg) {n”, ” // Request the server to send over a new figure.n”, ” fig.send_draw_message();n”, “};n”, “n”, “mpl.figure.prototype.handle_image_mode = function (fig, msg) {n”, ” fig.image_mode = msg[‘mode’];n”, “};n”, “n”, “mpl.figure.prototype.handle_history_buttons = function (fig, msg) {n”, ” for (var key in msg) {n”, ” if (!(key in fig.buttons)) {n”, ” continue;n”, ” }n”, ” fig.buttons[key].disabled = !msg[key];n”, ” fig.buttons[key].setAttribute(‘aria-disabled’, !msg[key]);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {n”, ” if (msg[‘mode’] === ‘PAN’) {n”, ” fig.buttons[‘Pan’].classList.add(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” } else if (msg[‘mode’] === ‘ZOOM’) {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.add(‘active’);n”, ” } else {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Called whenever the canvas gets updated.n”, ” this.send_message(‘ack’, {});n”, “};n”, “n”, “// A function to construct a web socket function for onmessage handling.n”, “// Called in the figure constructor.n”, “mpl.figure.prototype._make_on_message_function = function (fig) {n”, ” return function socket_on_message(evt) {n”, ” if (evt.data instanceof Blob) {n”, ” / FIXME: We get "Resource interpreted as Image butn”, ” * transferred with MIME type text/plain:" errors onn”, ” * Chrome. But how to set the MIME type? It doesn’t seemn”, ” * to be part of the websocket stream /n”, ” evt.data.type = ‘image/png’;n”, “n”, ” / Free the memory for the previous frames /n”, ” if (fig.imageObj.src) {n”, ” (window.URL || window.webkitURL).revokeObjectURL(n”, ” fig.imageObj.srcn”, ” );n”, ” }n”, “n”, ” fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(n”, ” evt.datan”, ” );n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” } else if (n”, ” typeof evt.data === ‘string’ &&n”, ” evt.data.slice(0, 21) === ‘data:image/png;base64’n”, ” ) {n”, ” fig.imageObj.src = evt.data;n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” }n”, “n”, ” var msg = JSON.parse(evt.data);n”, ” var msg_type = msg[‘type’];n”, “n”, ” // Call the "handle_{type}" callback, which takesn”, ” // the figure and JSON message as its only arguments.n”, ” try {n”, ” var callback = fig[‘handle_’ + msg_type];n”, ” } catch (e) {n”, ” console.log(n”, ” "No handler for the ‘" + msg_type + "’ message type: ",n”, ” msgn”, ” );n”, ” return;n”, ” }n”, “n”, ” if (callback) {n”, ” try {n”, ” // console.log("Handling ‘" + msg_type + "’ message: ", msg);n”, ” callback(fig, msg);n”, ” } catch (e) {n”, ” console.log(n”, ” "Exception inside the ‘handler_" + msg_type + "’ callback:",n”, ” e,n”, ” e.stack,n”, ” msgn”, ” );n”, ” }n”, ” }n”, ” };n”, “};n”, “n”, “// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvasn”, “mpl.findpos = function (e) {n”, ” //this section is from http://www.quirksmode.org/js/events_properties.htmln”, ” var targ;n”, ” if (!e) {n”, ” e = window.event;n”, ” }n”, ” if (e.target) {n”, ” targ = e.target;n”, ” } else if (e.srcElement) {n”, ” targ = e.srcElement;n”, ” }n”, ” if (targ.nodeType === 3) {n”, ” // defeat Safari bugn”, ” targ = targ.parentNode;n”, ” }n”, “n”, ” // pageX,Y are the mouse positions relative to the documentn”, ” var boundingRect = targ.getBoundingClientRect();n”, ” var x = e.pageX - (boundingRect.left + document.body.scrollLeft);n”, ” var y = e.pageY - (boundingRect.top + document.body.scrollTop);n”, “n”, ” return { x: x, y: y };n”, “};n”, “n”, “/n”, ” * return a copy of an object with only non-object keysn”, ” * we need this to avoid circular referencesn”, ” * http://stackoverflow.com/a/24161582/3208463n”, ” /n”, “function simpleKeys(original) {n”, ” return Object.keys(original).reduce(function (obj, key) {n”, ” if (typeof original[key] !== ‘object’) {n”, ” obj[key] = original[key];n”, ” }n”, ” return obj;n”, ” }, {});n”, “}n”, “n”, “mpl.figure.prototype.mouse_event = function (event, name) {n”, ” var canvas_pos = mpl.findpos(event);n”, “n”, ” if (name === ‘button_press’) {n”, ” this.canvas.focus();n”, ” this.canvas_div.focus();n”, ” }n”, “n”, ” var x = canvas_pos.x * this.ratio;n”, ” var y = canvas_pos.y * this.ratio;n”, “n”, ” this.send_message(name, {n”, ” x: x,n”, ” y: y,n”, ” button: event.button,n”, ” step: event.step,n”, ” guiEvent: simpleKeys(event),n”, ” });n”, “n”, ” / This prevents the web browser from automatically changing ton”, ” * the text insertion cursor when the button is pressed. We wantn”, ” * to control all of the cursor setting manually through then”, ” * ‘cursor’ event from matplotlib */n”, ” event.preventDefault();n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (_event, _name) {n”, ” // Handle any extra behaviour associated with a key eventn”, “};n”, “n”, “mpl.figure.prototype.key_event = function (event, name) {n”, ” // Prevent repeat eventsn”, ” if (name === ‘key_press’) {n”, ” if (event.which === this._key) {n”, ” return;n”, ” } else {n”, ” this._key = event.which;n”, ” }n”, ” }n”, ” if (name === ‘key_release’) {n”, ” this._key = null;n”, ” }n”, “n”, ” var value = ‘’;n”, ” if (event.ctrlKey && event.which !== 17) {n”, ” value += ‘ctrl+’;n”, ” }n”, ” if (event.altKey && event.which !== 18) {n”, ” value += ‘alt+’;n”, ” }n”, ” if (event.shiftKey && event.which !== 16) {n”, ” value += ‘shift+’;n”, ” }n”, “n”, ” value += ‘k’;n”, ” value += event.which.toString();n”, “n”, ” this._key_event_extra(event, name);n”, “n”, ” this.send_message(name, { key: value, guiEvent: simpleKeys(event) });n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onclick = function (name) {n”, ” if (name === ‘download’) {n”, ” this.handle_save(this, null);n”, ” } else {n”, ” this.send_message(‘toolbar_button’, { name: name });n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {n”, ” this.message.textContent = tooltip;n”, “};n”,
- <<<<<<< HEAD
“n”, “///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////n”, “// prettier-ignoren”, “var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError("Constructor requires ‘new’ operator");i.set(this,e)}function h(){throw new TypeError("Function is not a constructor")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-linen”,
“n”, “mpl.extensions = ["eps", "jpeg", "pdf", "png", "ps", "raw", "svg", "tif"];n”, “n”, “mpl.default_extension = "png";/* global mpl */n”, “n”, “var comm_websocket_adapter = function (comm) {n”, ” // Create a "websocket"-like object which calls the given IPython commn”, ” // object with the appropriate methods. Currently this is a non binaryn”, ” // socket, so there is still some room for performance tuning.n”, ” var ws = {};n”, “n”, ” ws.close = function () {n”, ” comm.close();n”, ” };n”, ” ws.send = function (m) {n”, ” //console.log(‘sending’, m);n”, ” comm.send(m);n”, ” };n”, ” // Register the callback with on_msg.n”, ” comm.on_msg(function (msg) {n”, ” //console.log(‘receiving’, msg[‘content’][‘data’], msg);n”, ” // Pass the mpl event to the overridden (by mpl) onmessage function.n”, ” ws.onmessage(msg[‘content’][‘data’]);n”, ” });n”, ” return ws;n”, “};n”, “n”, “mpl.mpl_figure_comm = function (comm, msg) {n”, ” // This is the function which gets called when the mpl processn”, ” // starts-up an IPython Comm through the "matplotlib" channel.n”, “n”, ” var id = msg.content.data.id;n”, ” // Get hold of the div created by the display call when the Commn”, ” // socket was opened in Python.n”, ” var element = document.getElementById(id);n”, ” var ws_proxy = comm_websocket_adapter(comm);n”, “n”, ” function ondownload(figure, _format) {n”, ” window.open(figure.canvas.toDataURL());n”, ” }n”, “n”, ” var fig = new mpl.figure(id, ws_proxy, ondownload, element);n”, “n”, ” // Call onopen now - mpl needs it, as it is assuming we’ve passed it a realn”, ” // web socket which is closed, not our websocket->open comm proxy.n”, ” ws_proxy.onopen();n”, “n”, ” fig.parent_element = element;n”, ” fig.cell_info = mpl.find_output_cell("<div id=’" + id + "’></div>");n”, ” if (!fig.cell_info) {n”, ” console.error(‘Failed to find cell for figure’, id, fig);n”, ” return;n”, ” }n”,
- <<<<<<< HEAD
” fig.cell_info[0].output_area.element.on(n”,
” ‘cleared’,n”, ” { fig: fig },n”, ” fig._remove_fig_handlern”, ” );n”, “};n”, “n”, “mpl.figure.prototype.handle_close = function (fig, msg) {n”, ” var width = fig.canvas.width / fig.ratio;n”, ” fig.cell_info[0].output_area.element.off(n”, ” ‘cleared’,n”, ” fig._remove_fig_handlern”, ” );n”,
- <<<<<<< HEAD
” fig.resizeObserverInstance.unobserve(fig.canvas_div);n”,
” // Update the output cell to use the data from the current canvas.n”, ” fig.push_to_output();n”, ” var dataURL = fig.canvas.toDataURL();n”, ” // Re-enable the keyboard manager in IPython - without this line, in FF,n”, ” // the notebook keyboard shortcuts fail.n”, ” IPython.keyboard_manager.enable();n”, ” fig.parent_element.innerHTML =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, ” fig.close_ws(fig, msg);n”, “};n”, “n”, “mpl.figure.prototype.close_ws = function (fig, msg) {n”, ” fig.send_message(‘closing’, msg);n”, ” // fig.ws.close()n”, “};n”, “n”, “mpl.figure.prototype.push_to_output = function (_remove_interactive) {n”, ” // Turn the data on the canvas into data in the output cell.n”, ” var width = this.canvas.width / this.ratio;n”, ” var dataURL = this.canvas.toDataURL();n”, ” this.cell_info[1][‘text/html’] =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Tell IPython that the notebook contents must change.n”, ” IPython.notebook.set_dirty(true);n”, ” this.send_message(‘ack’, {});n”, ” var fig = this;n”, ” // Wait a second, then push the new image to the DOM son”, ” // that it is saved nicely (might be nice to debounce this).n”, ” setTimeout(function () {n”, ” fig.push_to_output();n”, ” }, 1000);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘btn-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” var button;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. */n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” continue;n”, ” }n”, “n”, ” button = fig.buttons[name] = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-default’;n”, ” button.href = ‘#’;n”, ” button.title = name;n”, ” button.innerHTML = ‘<i class="fa ‘ + image + ‘ fa-lg"></i>’;n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” // Add the status bar.n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message pull-right’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “n”, ” // Add the close button to the window.n”, ” var buttongrp = document.createElement(‘div’);n”, ” buttongrp.classList = ‘btn-group inline pull-right’;n”, ” button = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-mini btn-primary’;n”, ” button.href = ‘#’;n”, ” button.title = ‘Stop Interaction’;n”, ” button.innerHTML = ‘<i class="fa fa-power-off icon-remove icon-large"></i>’;n”, ” button.addEventListener(‘click’, function (_evt) {n”, ” fig.handle_close(fig, {});n”, ” });n”, ” button.addEventListener(n”, ” ‘mouseover’,n”, ” on_mouseover_closure(‘Stop Interaction’)n”, ” );n”, ” buttongrp.appendChild(button);n”, ” var titlebar = this.root.querySelector(‘.ui-dialog-titlebar’);n”, ” titlebar.insertBefore(buttongrp, titlebar.firstChild);n”, “};n”, “n”, “mpl.figure.prototype._remove_fig_handler = function (event) {n”, ” var fig = event.data.fig;n”,
- <<<<<<< HEAD
” if (event.target !== this) {n”, ” // Ignore bubbled events from children.n”, ” return;n”, ” }n”,
“};n”, “n”, “mpl.figure.prototype._root_extra_style = function (el) {n”, ” el.style.boxSizing = ‘content-box’; // override notebook setting of border-box.n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (el) {n”, ” // this is important to make the div ‘focusablen”, ” el.setAttribute(‘tabindex’, 0);n”, ” // reach out to IPython and tell the keyboard manager to turn it’s selfn”, ” // off when our div gets focusn”, “n”, ” // location in version 3n”, ” if (IPython.notebook.keyboard_manager) {n”, ” IPython.notebook.keyboard_manager.register_events(el);n”, ” } else {n”, ” // location in version 2n”, ” IPython.keyboard_manager.register_events(el);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (event, _name) {n”, ” var manager = IPython.notebook.keyboard_manager;n”, ” if (!manager) {n”, ” manager = IPython.keyboard_manager;n”, ” }n”, “n”, ” // Check for shift+entern”, ” if (event.shiftKey && event.which === 13) {n”, ” this.canvas_div.blur();n”, ” // select the cell after this onen”, ” var index = IPython.notebook.find_cell_index(this.cell_info[0]);n”, ” IPython.notebook.select(index + 1);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” fig.ondownload(fig, null);n”, “};n”, “n”, “mpl.find_output_cell = function (html_output) {n”, ” // Return the cell and output element which can be found uniquely in the notebook.n”, ” // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"n”, ” // IPython event is triggered only after the cells have been serialised, which forn”, ” // our purposes (turning an active figure into a static one), is too late.n”, ” var cells = IPython.notebook.get_cells();n”, ” var ncells = cells.length;n”, ” for (var i = 0; i < ncells; i++) {n”, ” var cell = cells[i];n”, ” if (cell.cell_type === ‘code’) {n”, ” for (var j = 0; j < cell.output_area.outputs.length; j++) {n”, ” var data = cell.output_area.outputs[j];n”, ” if (data.data) {n”, ” // IPython >= 3 moved mimebundle to data attribute of outputn”, ” data = data.data;n”, ” }n”, ” if (data[‘text/html’] === html_output) {n”, ” return [cell, data, j];n”, ” }n”, ” }n”, ” }n”, ” }n”, “};n”, “n”, “// Register the function which deals with the matplotlib target/channel.n”, “// The kernel may be null if the page has been refreshed.n”, “if (IPython.notebook.kernel !== null) {n”, ” IPython.notebook.kernel.comm_manager.register_target(n”, ” ‘matplotlib’,n”, ” mpl.mpl_figure_commn”, ” );n”, “}n”
], “text/plain”: [
“<IPython.core.display.Javascript object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/html”: [
], “text/plain”: [
“<IPython.core.display.HTML object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}
], “source”: [
“try:n”, ” # close any open files before open new onen”, ” main_dataset.h5_dataset.file.close() n”, “except:n”, ” passn”, “main_dataset = ft.open_file("..\example_data\GOLD-NP-DIFF.dm3")n”, “main_dataset.plot()”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Finding the centern”, “n”, “### First try with cross correlation of rotated imagesn”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“### Cross- and Auto- Correlationn”, “n”, “Cross correlation and auto correlation are based on a multiplication in Fourier space. In the case of a an auto-correlation it is the same data while in the cross correlation it is another data (here the transposed (rotated) diffraction pattern)”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 3,
“metadata”: {}, “outputs”: [
- {
- “data”: {
- “application/javascript”: [
“/* Put everything inside the global mpl namespace /n”, “/ global mpl */n”, “window.mpl = {};n”, “n”, “mpl.get_websocket_type = function () {n”, ” if (typeof WebSocket !== ‘undefined’) {n”, ” return WebSocket;n”, ” } else if (typeof MozWebSocket !== ‘undefined’) {n”, ” return MozWebSocket;n”, ” } else {n”, ” alert(n”, ” ‘Your browser does not have WebSocket support. ‘ +n”, ” ‘Please try Chrome, Safari or Firefox ≥ 6. ‘ +n”, ” ‘Firefox 4 and 5 are also supported but you ‘ +n”, ” ‘have to enable WebSockets in about:config.’n”, ” );n”, ” }n”, “};n”, “n”, “mpl.figure = function (figure_id, websocket, ondownload, parent_element) {n”, ” this.id = figure_id;n”, “n”, ” this.ws = websocket;n”, “n”, ” this.supports_binary = this.ws.binaryType !== undefined;n”, “n”, ” if (!this.supports_binary) {n”, ” var warnings = document.getElementById(‘mpl-warnings’);n”, ” if (warnings) {n”, ” warnings.style.display = ‘block’;n”, ” warnings.textContent =n”, ” ‘This browser does not support binary websocket messages. ‘ +n”, ” ‘Performance may be slow.’;n”, ” }n”, ” }n”, “n”, ” this.imageObj = new Image();n”, “n”, ” this.context = undefined;n”, ” this.message = undefined;n”, ” this.canvas = undefined;n”, ” this.rubberband_canvas = undefined;n”, ” this.rubberband_context = undefined;n”, ” this.format_dropdown = undefined;n”, “n”, ” this.image_mode = ‘full’;n”, “n”, ” this.root = document.createElement(‘div’);n”, ” this.root.setAttribute(‘style’, ‘display: inline-block’);n”, ” this._root_extra_style(this.root);n”, “n”, ” parent_element.appendChild(this.root);n”, “n”, ” this._init_header(this);n”, ” this._init_canvas(this);n”, ” this._init_toolbar(this);n”, “n”, ” var fig = this;n”, “n”, ” this.waiting = false;n”, “n”, ” this.ws.onopen = function () {n”, ” fig.send_message(‘supports_binary’, { value: fig.supports_binary });n”, ” fig.send_message(‘send_image_mode’, {});n”, ” if (fig.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: fig.ratio });n”, ” }n”, ” fig.send_message(‘refresh’, {});n”, ” };n”, “n”, ” this.imageObj.onload = function () {n”, ” if (fig.image_mode === ‘full’) {n”, ” // Full images could contain transparency (where diff imagesn”, ” // almost always do), so we need to clear the canvas so thatn”, ” // there is no ghosting.n”, ” fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);n”, ” }n”, ” fig.context.drawImage(fig.imageObj, 0, 0);n”, ” };n”, “n”, ” this.imageObj.onunload = function () {n”, ” fig.ws.close();n”, ” };n”, “n”, ” this.ws.onmessage = this._make_on_message_function(this);n”, “n”, ” this.ondownload = ondownload;n”, “};n”, “n”, “mpl.figure.prototype._init_header = function () {n”, ” var titlebar = document.createElement(‘div’);n”, ” titlebar.classList =n”, ” ‘ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix’;n”, ” var titletext = document.createElement(‘div’);n”, ” titletext.classList = ‘ui-dialog-title’;n”, ” titletext.setAttribute(n”, ” ‘style’,n”, ” ‘width: 100%; text-align: center; padding: 3px;’n”, ” );n”, ” titlebar.appendChild(titletext);n”, ” this.root.appendChild(titlebar);n”, ” this.header = titletext;n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._root_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._init_canvas = function () {n”, ” var fig = this;n”, “n”, ” var canvas_div = (this.canvas_div = document.createElement(‘div’));n”, ” canvas_div.setAttribute(n”, ” ‘style’,n”, ” ‘border: 1px solid #ddd;’ +n”, ” ‘box-sizing: content-box;’ +n”, ” ‘clear: both;’ +n”, ” ‘min-height: 1px;’ +n”, ” ‘min-width: 1px;’ +n”, ” ‘outline: 0;’ +n”, ” ‘overflow: hidden;’ +n”, ” ‘position: relative;’ +n”, ” ‘resize: both;’n”, ” );n”, “n”, ” function on_keyboard_event_closure(name) {n”, ” return function (event) {n”, ” return fig.key_event(event, name);n”, ” };n”, ” }n”, “n”, ” canvas_div.addEventListener(n”, ” ‘keydown’,n”, ” on_keyboard_event_closure(‘key_press’)n”, ” );n”, ” canvas_div.addEventListener(n”, ” ‘keyup’,n”, ” on_keyboard_event_closure(‘key_release’)n”, ” );n”, “n”, ” this._canvas_extra_style(canvas_div);n”, ” this.root.appendChild(canvas_div);n”, “n”, ” var canvas = (this.canvas = document.createElement(‘canvas’));n”, ” canvas.classList.add(‘mpl-canvas’);n”, ” canvas.setAttribute(‘style’, ‘box-sizing: content-box;’);n”, “n”, ” this.context = canvas.getContext(‘2d’);n”, “n”, ” var backingStore =n”, ” this.context.backingStorePixelRatio ||n”, ” this.context.webkitBackingStorePixelRatio ||n”, ” this.context.mozBackingStorePixelRatio ||n”, ” this.context.msBackingStorePixelRatio ||n”, ” this.context.oBackingStorePixelRatio ||n”, ” this.context.backingStorePixelRatio ||n”, ” 1;n”, “n”, ” this.ratio = (window.devicePixelRatio || 1) / backingStore;n”, ” if (this.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: this.ratio });n”, ” }n”, “n”, ” var rubberband_canvas = (this.rubberband_canvas = document.createElement(n”, ” ‘canvas’n”, ” ));n”, ” rubberband_canvas.setAttribute(n”, ” ‘style’,n”, ” ‘box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;’n”, ” );n”, “n”,
- <<<<<<< HEAD
” // Apply a ponyfill if ResizeObserver is not implemented by browser.n”, ” if (this.ResizeObserver === undefined) {n”, ” if (window.ResizeObserver !== undefined) {n”, ” this.ResizeObserver = window.ResizeObserver;n”, ” } else {n”, ” var obs = _JSXTOOLS_RESIZE_OBSERVER({});n”, ” this.ResizeObserver = obs.ResizeObserver;n”, ” }n”, ” }n”, “n”, ” this.resizeObserverInstance = new this.ResizeObserver(function (entries) {n”,
” var nentries = entries.length;n”, ” for (var i = 0; i < nentries; i++) {n”, ” var entry = entries[i];n”, ” var width, height;n”, ” if (entry.contentBoxSize) {n”, ” if (entry.contentBoxSize instanceof Array) {n”, ” // Chrome 84 implements new version of spec.n”, ” width = entry.contentBoxSize[0].inlineSize;n”, ” height = entry.contentBoxSize[0].blockSize;n”, ” } else {n”, ” // Firefox implements old version of spec.n”, ” width = entry.contentBoxSize.inlineSize;n”, ” height = entry.contentBoxSize.blockSize;n”, ” }n”, ” } else {n”, ” // Chrome <84 implements even older version of spec.n”, ” width = entry.contentRect.width;n”, ” height = entry.contentRect.height;n”, ” }n”, “n”, ” // Keep the size of the canvas and rubber band canvas in sync withn”, ” // the canvas container.n”, ” if (entry.devicePixelContentBoxSize) {n”, ” // Chrome 84 implements new version of spec.n”, ” canvas.setAttribute(n”, ” ‘width’,n”, ” entry.devicePixelContentBoxSize[0].inlineSizen”, ” );n”, ” canvas.setAttribute(n”, ” ‘height’,n”, ” entry.devicePixelContentBoxSize[0].blockSizen”, ” );n”, ” } else {n”, ” canvas.setAttribute(‘width’, width * fig.ratio);n”, ” canvas.setAttribute(‘height’, height * fig.ratio);n”, ” }n”, ” canvas.setAttribute(n”, ” ‘style’,n”, ” ‘width: ‘ + width + ‘px; height: ‘ + height + ‘px;’n”, ” );n”, “n”, ” rubberband_canvas.setAttribute(‘width’, width);n”, ” rubberband_canvas.setAttribute(‘height’, height);n”, “n”, ” // And update the size in Python. We ignore the initial 0/0 sizen”, ” // that occurs as the element is placed into the DOM, which shouldn”, ” // otherwise not happen due to the minimum size styling.n”, ” if (width != 0 && height != 0) {n”, ” fig.request_resize(width, height);n”, ” }n”, ” }n”, ” });n”,
- <<<<<<< HEAD
” this.resizeObserverInstance.observe(canvas_div);n”,
“n”, ” function on_mouse_event_closure(name) {n”, ” return function (event) {n”, ” return fig.mouse_event(event, name);n”, ” };n”, ” }n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousedown’,n”, ” on_mouse_event_closure(‘button_press’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseup’,n”, ” on_mouse_event_closure(‘button_release’)n”, ” );n”, ” // Throttle sequential mouse events to 1 every 20ms.n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousemove’,n”, ” on_mouse_event_closure(‘motion_notify’)n”, ” );n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseenter’,n”, ” on_mouse_event_closure(‘figure_enter’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseleave’,n”, ” on_mouse_event_closure(‘figure_leave’)n”, ” );n”, “n”, ” canvas_div.addEventListener(‘wheel’, function (event) {n”, ” if (event.deltaY < 0) {n”, ” event.step = 1;n”, ” } else {n”, ” event.step = -1;n”, ” }n”, ” on_mouse_event_closure(‘scroll’)(event);n”, ” });n”, “n”, ” canvas_div.appendChild(canvas);n”, ” canvas_div.appendChild(rubberband_canvas);n”, “n”, ” this.rubberband_context = rubberband_canvas.getContext(‘2d’);n”, ” this.rubberband_context.strokeStyle = ‘#000000’;n”, “n”, ” this._resize_canvas = function (width, height, forward) {n”, ” if (forward) {n”, ” canvas_div.style.width = width + ‘px’;n”, ” canvas_div.style.height = height + ‘px’;n”, ” }n”, ” };n”, “n”, ” // Disable right mouse context menu.n”, ” this.rubberband_canvas.addEventListener(‘contextmenu’, function (_e) {n”, ” event.preventDefault();n”, ” return false;n”, ” });n”, “n”, ” function set_focus() {n”, ” canvas.focus();n”, ” canvas_div.focus();n”, ” }n”, “n”, ” window.setTimeout(set_focus, 100);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘mpl-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. /n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” continue;n”, ” }n”, “n”, ” var button = (fig.buttons[name] = document.createElement(‘button’));n”, ” button.classList = ‘mpl-widget’;n”, ” button.setAttribute(‘role’, ‘button’);n”, ” button.setAttribute(‘aria-disabled’, ‘false’);n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, “n”, ” var icon_img = document.createElement(‘img’);n”, ” icon_img.src = ‘_images/’ + image + ‘.png’;n”, ” icon_img.srcset = ‘_images/’ + image + ‘_large.png 2x’;n”, ” icon_img.alt = tooltip;n”, ” button.appendChild(icon_img);n”, “n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” var fmt_picker = document.createElement(‘select’);n”, ” fmt_picker.classList = ‘mpl-widget’;n”, ” toolbar.appendChild(fmt_picker);n”, ” this.format_dropdown = fmt_picker;n”, “n”, ” for (var ind in mpl.extensions) {n”, ” var fmt = mpl.extensions[ind];n”, ” var option = document.createElement(‘option’);n”, ” option.selected = fmt === mpl.default_extension;n”, ” option.innerHTML = fmt;n”, ” fmt_picker.appendChild(option);n”, ” }n”, “n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “};n”, “n”, “mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {n”, ” // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,n”, ” // which will in turn request a refresh of the image.n”, ” this.send_message(‘resize’, { width: x_pixels, height: y_pixels });n”, “};n”, “n”, “mpl.figure.prototype.send_message = function (type, properties) {n”, ” properties[‘type’] = type;n”, ” properties[‘figure_id’] = this.id;n”, ” this.ws.send(JSON.stringify(properties));n”, “};n”, “n”, “mpl.figure.prototype.send_draw_message = function () {n”, ” if (!this.waiting) {n”, ” this.waiting = true;n”, ” this.ws.send(JSON.stringify({ type: ‘draw’, figure_id: this.id }));n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” var format_dropdown = fig.format_dropdown;n”, ” var format = format_dropdown.options[format_dropdown.selectedIndex].value;n”, ” fig.ondownload(fig, format);n”, “};n”, “n”, “mpl.figure.prototype.handle_resize = function (fig, msg) {n”, ” var size = msg[‘size’];n”, ” if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {n”, ” fig._resize_canvas(size[0], size[1], msg[‘forward’]);n”, ” fig.send_message(‘refresh’, {});n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_rubberband = function (fig, msg) {n”, ” var x0 = msg[‘x0’] / fig.ratio;n”, ” var y0 = (fig.canvas.height - msg[‘y0’]) / fig.ratio;n”, ” var x1 = msg[‘x1’] / fig.ratio;n”, ” var y1 = (fig.canvas.height - msg[‘y1’]) / fig.ratio;n”, ” x0 = Math.floor(x0) + 0.5;n”, ” y0 = Math.floor(y0) + 0.5;n”, ” x1 = Math.floor(x1) + 0.5;n”, ” y1 = Math.floor(y1) + 0.5;n”, ” var min_x = Math.min(x0, x1);n”, ” var min_y = Math.min(y0, y1);n”, ” var width = Math.abs(x1 - x0);n”, ” var height = Math.abs(y1 - y0);n”, “n”, ” fig.rubberband_context.clearRect(n”, ” 0,n”, ” 0,n”, ” fig.canvas.width / fig.ratio,n”, ” fig.canvas.height / fig.ration”, ” );n”, “n”, ” fig.rubberband_context.strokeRect(min_x, min_y, width, height);n”, “};n”, “n”, “mpl.figure.prototype.handle_figure_label = function (fig, msg) {n”, ” // Updates the figure title.n”, ” fig.header.textContent = msg[‘label’];n”, “};n”, “n”, “mpl.figure.prototype.handle_cursor = function (fig, msg) {n”, ” var cursor = msg[‘cursor’];n”, ” switch (cursor) {n”, ” case 0:n”, ” cursor = ‘pointer’;n”, ” break;n”, ” case 1:n”, ” cursor = ‘default’;n”, ” break;n”, ” case 2:n”, ” cursor = ‘crosshair’;n”, ” break;n”, ” case 3:n”, ” cursor = ‘move’;n”, ” break;n”, ” }n”, ” fig.rubberband_canvas.style.cursor = cursor;n”, “};n”, “n”, “mpl.figure.prototype.handle_message = function (fig, msg) {n”, ” fig.message.textContent = msg[‘message’];n”, “};n”, “n”, “mpl.figure.prototype.handle_draw = function (fig, _msg) {n”, ” // Request the server to send over a new figure.n”, ” fig.send_draw_message();n”, “};n”, “n”, “mpl.figure.prototype.handle_image_mode = function (fig, msg) {n”, ” fig.image_mode = msg[‘mode’];n”, “};n”, “n”, “mpl.figure.prototype.handle_history_buttons = function (fig, msg) {n”, ” for (var key in msg) {n”, ” if (!(key in fig.buttons)) {n”, ” continue;n”, ” }n”, ” fig.buttons[key].disabled = !msg[key];n”, ” fig.buttons[key].setAttribute(‘aria-disabled’, !msg[key]);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {n”, ” if (msg[‘mode’] === ‘PAN’) {n”, ” fig.buttons[‘Pan’].classList.add(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” } else if (msg[‘mode’] === ‘ZOOM’) {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.add(‘active’);n”, ” } else {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Called whenever the canvas gets updated.n”, ” this.send_message(‘ack’, {});n”, “};n”, “n”, “// A function to construct a web socket function for onmessage handling.n”, “// Called in the figure constructor.n”, “mpl.figure.prototype._make_on_message_function = function (fig) {n”, ” return function socket_on_message(evt) {n”, ” if (evt.data instanceof Blob) {n”, ” / FIXME: We get "Resource interpreted as Image butn”, ” * transferred with MIME type text/plain:" errors onn”, ” * Chrome. But how to set the MIME type? It doesn’t seemn”, ” * to be part of the websocket stream /n”, ” evt.data.type = ‘image/png’;n”, “n”, ” / Free the memory for the previous frames /n”, ” if (fig.imageObj.src) {n”, ” (window.URL || window.webkitURL).revokeObjectURL(n”, ” fig.imageObj.srcn”, ” );n”, ” }n”, “n”, ” fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(n”, ” evt.datan”, ” );n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” } else if (n”, ” typeof evt.data === ‘string’ &&n”, ” evt.data.slice(0, 21) === ‘data:image/png;base64’n”, ” ) {n”, ” fig.imageObj.src = evt.data;n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” }n”, “n”, ” var msg = JSON.parse(evt.data);n”, ” var msg_type = msg[‘type’];n”, “n”, ” // Call the "handle_{type}" callback, which takesn”, ” // the figure and JSON message as its only arguments.n”, ” try {n”, ” var callback = fig[‘handle_’ + msg_type];n”, ” } catch (e) {n”, ” console.log(n”, ” "No handler for the ‘" + msg_type + "’ message type: ",n”, ” msgn”, ” );n”, ” return;n”, ” }n”, “n”, ” if (callback) {n”, ” try {n”, ” // console.log("Handling ‘" + msg_type + "’ message: ", msg);n”, ” callback(fig, msg);n”, ” } catch (e) {n”, ” console.log(n”, ” "Exception inside the ‘handler_" + msg_type + "’ callback:",n”, ” e,n”, ” e.stack,n”, ” msgn”, ” );n”, ” }n”, ” }n”, ” };n”, “};n”, “n”, “// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvasn”, “mpl.findpos = function (e) {n”, ” //this section is from http://www.quirksmode.org/js/events_properties.htmln”, ” var targ;n”, ” if (!e) {n”, ” e = window.event;n”, ” }n”, ” if (e.target) {n”, ” targ = e.target;n”, ” } else if (e.srcElement) {n”, ” targ = e.srcElement;n”, ” }n”, ” if (targ.nodeType === 3) {n”, ” // defeat Safari bugn”, ” targ = targ.parentNode;n”, ” }n”, “n”, ” // pageX,Y are the mouse positions relative to the documentn”, ” var boundingRect = targ.getBoundingClientRect();n”, ” var x = e.pageX - (boundingRect.left + document.body.scrollLeft);n”, ” var y = e.pageY - (boundingRect.top + document.body.scrollTop);n”, “n”, ” return { x: x, y: y };n”, “};n”, “n”, “/n”, ” * return a copy of an object with only non-object keysn”, ” * we need this to avoid circular referencesn”, ” * http://stackoverflow.com/a/24161582/3208463n”, ” /n”, “function simpleKeys(original) {n”, ” return Object.keys(original).reduce(function (obj, key) {n”, ” if (typeof original[key] !== ‘object’) {n”, ” obj[key] = original[key];n”, ” }n”, ” return obj;n”, ” }, {});n”, “}n”, “n”, “mpl.figure.prototype.mouse_event = function (event, name) {n”, ” var canvas_pos = mpl.findpos(event);n”, “n”, ” if (name === ‘button_press’) {n”, ” this.canvas.focus();n”, ” this.canvas_div.focus();n”, ” }n”, “n”, ” var x = canvas_pos.x * this.ratio;n”, ” var y = canvas_pos.y * this.ratio;n”, “n”, ” this.send_message(name, {n”, ” x: x,n”, ” y: y,n”, ” button: event.button,n”, ” step: event.step,n”, ” guiEvent: simpleKeys(event),n”, ” });n”, “n”, ” / This prevents the web browser from automatically changing ton”, ” * the text insertion cursor when the button is pressed. We wantn”, ” * to control all of the cursor setting manually through then”, ” * ‘cursor’ event from matplotlib */n”, ” event.preventDefault();n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (_event, _name) {n”, ” // Handle any extra behaviour associated with a key eventn”, “};n”, “n”, “mpl.figure.prototype.key_event = function (event, name) {n”, ” // Prevent repeat eventsn”, ” if (name === ‘key_press’) {n”, ” if (event.which === this._key) {n”, ” return;n”, ” } else {n”, ” this._key = event.which;n”, ” }n”, ” }n”, ” if (name === ‘key_release’) {n”, ” this._key = null;n”, ” }n”, “n”, ” var value = ‘’;n”, ” if (event.ctrlKey && event.which !== 17) {n”, ” value += ‘ctrl+’;n”, ” }n”, ” if (event.altKey && event.which !== 18) {n”, ” value += ‘alt+’;n”, ” }n”, ” if (event.shiftKey && event.which !== 16) {n”, ” value += ‘shift+’;n”, ” }n”, “n”, ” value += ‘k’;n”, ” value += event.which.toString();n”, “n”, ” this._key_event_extra(event, name);n”, “n”, ” this.send_message(name, { key: value, guiEvent: simpleKeys(event) });n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onclick = function (name) {n”, ” if (name === ‘download’) {n”, ” this.handle_save(this, null);n”, ” } else {n”, ” this.send_message(‘toolbar_button’, { name: name });n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {n”, ” this.message.textContent = tooltip;n”, “};n”,
- <<<<<<< HEAD
“n”, “///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////n”, “// prettier-ignoren”, “var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError("Constructor requires ‘new’ operator");i.set(this,e)}function h(){throw new TypeError("Function is not a constructor")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-linen”,
“n”, “mpl.extensions = ["eps", "jpeg", "pdf", "png", "ps", "raw", "svg", "tif"];n”, “n”, “mpl.default_extension = "png";/* global mpl */n”, “n”, “var comm_websocket_adapter = function (comm) {n”, ” // Create a "websocket"-like object which calls the given IPython commn”, ” // object with the appropriate methods. Currently this is a non binaryn”, ” // socket, so there is still some room for performance tuning.n”, ” var ws = {};n”, “n”, ” ws.close = function () {n”, ” comm.close();n”, ” };n”, ” ws.send = function (m) {n”, ” //console.log(‘sending’, m);n”, ” comm.send(m);n”, ” };n”, ” // Register the callback with on_msg.n”, ” comm.on_msg(function (msg) {n”, ” //console.log(‘receiving’, msg[‘content’][‘data’], msg);n”, ” // Pass the mpl event to the overridden (by mpl) onmessage function.n”, ” ws.onmessage(msg[‘content’][‘data’]);n”, ” });n”, ” return ws;n”, “};n”, “n”, “mpl.mpl_figure_comm = function (comm, msg) {n”, ” // This is the function which gets called when the mpl processn”, ” // starts-up an IPython Comm through the "matplotlib" channel.n”, “n”, ” var id = msg.content.data.id;n”, ” // Get hold of the div created by the display call when the Commn”, ” // socket was opened in Python.n”, ” var element = document.getElementById(id);n”, ” var ws_proxy = comm_websocket_adapter(comm);n”, “n”, ” function ondownload(figure, _format) {n”, ” window.open(figure.canvas.toDataURL());n”, ” }n”, “n”, ” var fig = new mpl.figure(id, ws_proxy, ondownload, element);n”, “n”, ” // Call onopen now - mpl needs it, as it is assuming we’ve passed it a realn”, ” // web socket which is closed, not our websocket->open comm proxy.n”, ” ws_proxy.onopen();n”, “n”, ” fig.parent_element = element;n”, ” fig.cell_info = mpl.find_output_cell("<div id=’" + id + "’></div>");n”, ” if (!fig.cell_info) {n”, ” console.error(‘Failed to find cell for figure’, id, fig);n”, ” return;n”, ” }n”,
- <<<<<<< HEAD
” fig.cell_info[0].output_area.element.on(n”,
” ‘cleared’,n”, ” { fig: fig },n”, ” fig._remove_fig_handlern”, ” );n”, “};n”, “n”, “mpl.figure.prototype.handle_close = function (fig, msg) {n”, ” var width = fig.canvas.width / fig.ratio;n”, ” fig.cell_info[0].output_area.element.off(n”, ” ‘cleared’,n”, ” fig._remove_fig_handlern”, ” );n”,
- <<<<<<< HEAD
” fig.resizeObserverInstance.unobserve(fig.canvas_div);n”,
” // Update the output cell to use the data from the current canvas.n”, ” fig.push_to_output();n”, ” var dataURL = fig.canvas.toDataURL();n”, ” // Re-enable the keyboard manager in IPython - without this line, in FF,n”, ” // the notebook keyboard shortcuts fail.n”, ” IPython.keyboard_manager.enable();n”, ” fig.parent_element.innerHTML =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, ” fig.close_ws(fig, msg);n”, “};n”, “n”, “mpl.figure.prototype.close_ws = function (fig, msg) {n”, ” fig.send_message(‘closing’, msg);n”, ” // fig.ws.close()n”, “};n”, “n”, “mpl.figure.prototype.push_to_output = function (_remove_interactive) {n”, ” // Turn the data on the canvas into data in the output cell.n”, ” var width = this.canvas.width / this.ratio;n”, ” var dataURL = this.canvas.toDataURL();n”, ” this.cell_info[1][‘text/html’] =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Tell IPython that the notebook contents must change.n”, ” IPython.notebook.set_dirty(true);n”, ” this.send_message(‘ack’, {});n”, ” var fig = this;n”, ” // Wait a second, then push the new image to the DOM son”, ” // that it is saved nicely (might be nice to debounce this).n”, ” setTimeout(function () {n”, ” fig.push_to_output();n”, ” }, 1000);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘btn-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” var button;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. */n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” continue;n”, ” }n”, “n”, ” button = fig.buttons[name] = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-default’;n”, ” button.href = ‘#’;n”, ” button.title = name;n”, ” button.innerHTML = ‘<i class="fa ‘ + image + ‘ fa-lg"></i>’;n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” // Add the status bar.n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message pull-right’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “n”, ” // Add the close button to the window.n”, ” var buttongrp = document.createElement(‘div’);n”, ” buttongrp.classList = ‘btn-group inline pull-right’;n”, ” button = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-mini btn-primary’;n”, ” button.href = ‘#’;n”, ” button.title = ‘Stop Interaction’;n”, ” button.innerHTML = ‘<i class="fa fa-power-off icon-remove icon-large"></i>’;n”, ” button.addEventListener(‘click’, function (_evt) {n”, ” fig.handle_close(fig, {});n”, ” });n”, ” button.addEventListener(n”, ” ‘mouseover’,n”, ” on_mouseover_closure(‘Stop Interaction’)n”, ” );n”, ” buttongrp.appendChild(button);n”, ” var titlebar = this.root.querySelector(‘.ui-dialog-titlebar’);n”, ” titlebar.insertBefore(buttongrp, titlebar.firstChild);n”, “};n”, “n”, “mpl.figure.prototype._remove_fig_handler = function (event) {n”, ” var fig = event.data.fig;n”,
- <<<<<<< HEAD
” if (event.target !== this) {n”, ” // Ignore bubbled events from children.n”, ” return;n”, ” }n”,
“};n”, “n”, “mpl.figure.prototype._root_extra_style = function (el) {n”, ” el.style.boxSizing = ‘content-box’; // override notebook setting of border-box.n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (el) {n”, ” // this is important to make the div ‘focusablen”, ” el.setAttribute(‘tabindex’, 0);n”, ” // reach out to IPython and tell the keyboard manager to turn it’s selfn”, ” // off when our div gets focusn”, “n”, ” // location in version 3n”, ” if (IPython.notebook.keyboard_manager) {n”, ” IPython.notebook.keyboard_manager.register_events(el);n”, ” } else {n”, ” // location in version 2n”, ” IPython.keyboard_manager.register_events(el);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (event, _name) {n”, ” var manager = IPython.notebook.keyboard_manager;n”, ” if (!manager) {n”, ” manager = IPython.keyboard_manager;n”, ” }n”, “n”, ” // Check for shift+entern”, ” if (event.shiftKey && event.which === 13) {n”, ” this.canvas_div.blur();n”, ” // select the cell after this onen”, ” var index = IPython.notebook.find_cell_index(this.cell_info[0]);n”, ” IPython.notebook.select(index + 1);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” fig.ondownload(fig, null);n”, “};n”, “n”, “mpl.find_output_cell = function (html_output) {n”, ” // Return the cell and output element which can be found uniquely in the notebook.n”, ” // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"n”, ” // IPython event is triggered only after the cells have been serialised, which forn”, ” // our purposes (turning an active figure into a static one), is too late.n”, ” var cells = IPython.notebook.get_cells();n”, ” var ncells = cells.length;n”, ” for (var i = 0; i < ncells; i++) {n”, ” var cell = cells[i];n”, ” if (cell.cell_type === ‘code’) {n”, ” for (var j = 0; j < cell.output_area.outputs.length; j++) {n”, ” var data = cell.output_area.outputs[j];n”, ” if (data.data) {n”, ” // IPython >= 3 moved mimebundle to data attribute of outputn”, ” data = data.data;n”, ” }n”, ” if (data[‘text/html’] === html_output) {n”, ” return [cell, data, j];n”, ” }n”, ” }n”, ” }n”, ” }n”, “};n”, “n”, “// Register the function which deals with the matplotlib target/channel.n”, “// The kernel may be null if the page has been refreshed.n”, “if (IPython.notebook.kernel !== null) {n”, ” IPython.notebook.kernel.comm_manager.register_target(n”, ” ‘matplotlib’,n”, ” mpl.mpl_figure_commn”, ” );n”, “}n”
], “text/plain”: [
“<IPython.core.display.Javascript object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/html”: [
], “text/plain”: [
“<IPython.core.display.HTML object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“center = (dask.array<getitem, shape=(), dtype=int64, chunksize=(), chunktype=numpy.ndarray>, dask.array<getitem, shape=(), dtype=int64, chunksize=(), chunktype=numpy.ndarray>) which is a shift of 66.0 px in x and 158.0 px in y directionn”
]
}
], “source”: [
“## Access the data of the loaded imagen”, “n”, “diff_pattern = main_datasetn”, “diff_pattern = diff_pattern-diff_pattern.min()n”, “correlation = ‘auto’n”, “dif_ft = np.fft.fft2(diff_pattern)n”, “if correlation == ‘auto’:n”, ” auto_correlation = np.fft.fftshift(np.fft.ifft2(dif_ft*dif_ft))n”, ” center = np.unravel_index(np.argmax(auto_correlation.real, axis=None), auto_correlation.real.shape)n”, ” plt.figure()n”, ” plt.title(‘Auto-Correlation’)n”, ” plt.imshow(auto_correlation.real);n”, “else: n”, ” dif_ft2 = np.fft.fft2(diff_pattern.T)n”, ” cross_correlation = np.fft.fftshift(np.fft.ifft2(dif_ft*dif_ft2))n”, ” center = np.unravel_index(np.argmax(cross_correlation.real, axis=None), cross_correlation.real.shape)n”, ” plt.figure()n”, ” plt.title(‘Cross-Correlation’)n”, ” plt.imshow(auto_correlation.real);n”, ” n”, “shift = np.array(center - np.array(dif_ft.shape)/2)n”, “print(f’center = {center} which is a shift of {shift[0]} px in x and {shift[1]} px in y direction’)n”, “plt.scatter([center[1]],[center[0]]);”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“### How well did we do?n”, “n”, “### Select the center yourselfn”, “n”, “The beam stop confuses the cross correlation sometimes and then we need to adjust the selection”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 4,
- “metadata”: {
“scrolled”: false
}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“[-958 -866]n”
]
}, {
- “data”: {
- “application/javascript”: [
“/* Put everything inside the global mpl namespace /n”, “/ global mpl */n”, “window.mpl = {};n”, “n”, “mpl.get_websocket_type = function () {n”, ” if (typeof WebSocket !== ‘undefined’) {n”, ” return WebSocket;n”, ” } else if (typeof MozWebSocket !== ‘undefined’) {n”, ” return MozWebSocket;n”, ” } else {n”, ” alert(n”, ” ‘Your browser does not have WebSocket support. ‘ +n”, ” ‘Please try Chrome, Safari or Firefox ≥ 6. ‘ +n”, ” ‘Firefox 4 and 5 are also supported but you ‘ +n”, ” ‘have to enable WebSockets in about:config.’n”, ” );n”, ” }n”, “};n”, “n”, “mpl.figure = function (figure_id, websocket, ondownload, parent_element) {n”, ” this.id = figure_id;n”, “n”, ” this.ws = websocket;n”, “n”, ” this.supports_binary = this.ws.binaryType !== undefined;n”, “n”, ” if (!this.supports_binary) {n”, ” var warnings = document.getElementById(‘mpl-warnings’);n”, ” if (warnings) {n”, ” warnings.style.display = ‘block’;n”, ” warnings.textContent =n”, ” ‘This browser does not support binary websocket messages. ‘ +n”, ” ‘Performance may be slow.’;n”, ” }n”, ” }n”, “n”, ” this.imageObj = new Image();n”, “n”, ” this.context = undefined;n”, ” this.message = undefined;n”, ” this.canvas = undefined;n”, ” this.rubberband_canvas = undefined;n”, ” this.rubberband_context = undefined;n”, ” this.format_dropdown = undefined;n”, “n”, ” this.image_mode = ‘full’;n”, “n”, ” this.root = document.createElement(‘div’);n”, ” this.root.setAttribute(‘style’, ‘display: inline-block’);n”, ” this._root_extra_style(this.root);n”, “n”, ” parent_element.appendChild(this.root);n”, “n”, ” this._init_header(this);n”, ” this._init_canvas(this);n”, ” this._init_toolbar(this);n”, “n”, ” var fig = this;n”, “n”, ” this.waiting = false;n”, “n”, ” this.ws.onopen = function () {n”, ” fig.send_message(‘supports_binary’, { value: fig.supports_binary });n”, ” fig.send_message(‘send_image_mode’, {});n”, ” if (fig.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: fig.ratio });n”, ” }n”, ” fig.send_message(‘refresh’, {});n”, ” };n”, “n”, ” this.imageObj.onload = function () {n”, ” if (fig.image_mode === ‘full’) {n”, ” // Full images could contain transparency (where diff imagesn”, ” // almost always do), so we need to clear the canvas so thatn”, ” // there is no ghosting.n”, ” fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);n”, ” }n”, ” fig.context.drawImage(fig.imageObj, 0, 0);n”, ” };n”, “n”, ” this.imageObj.onunload = function () {n”, ” fig.ws.close();n”, ” };n”, “n”, ” this.ws.onmessage = this._make_on_message_function(this);n”, “n”, ” this.ondownload = ondownload;n”, “};n”, “n”, “mpl.figure.prototype._init_header = function () {n”, ” var titlebar = document.createElement(‘div’);n”, ” titlebar.classList =n”, ” ‘ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix’;n”, ” var titletext = document.createElement(‘div’);n”, ” titletext.classList = ‘ui-dialog-title’;n”, ” titletext.setAttribute(n”, ” ‘style’,n”, ” ‘width: 100%; text-align: center; padding: 3px;’n”, ” );n”, ” titlebar.appendChild(titletext);n”, ” this.root.appendChild(titlebar);n”, ” this.header = titletext;n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._root_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._init_canvas = function () {n”, ” var fig = this;n”, “n”, ” var canvas_div = (this.canvas_div = document.createElement(‘div’));n”, ” canvas_div.setAttribute(n”, ” ‘style’,n”, ” ‘border: 1px solid #ddd;’ +n”, ” ‘box-sizing: content-box;’ +n”, ” ‘clear: both;’ +n”, ” ‘min-height: 1px;’ +n”, ” ‘min-width: 1px;’ +n”, ” ‘outline: 0;’ +n”, ” ‘overflow: hidden;’ +n”, ” ‘position: relative;’ +n”, ” ‘resize: both;’n”, ” );n”, “n”, ” function on_keyboard_event_closure(name) {n”, ” return function (event) {n”, ” return fig.key_event(event, name);n”, ” };n”, ” }n”, “n”, ” canvas_div.addEventListener(n”, ” ‘keydown’,n”, ” on_keyboard_event_closure(‘key_press’)n”, ” );n”, ” canvas_div.addEventListener(n”, ” ‘keyup’,n”, ” on_keyboard_event_closure(‘key_release’)n”, ” );n”, “n”, ” this._canvas_extra_style(canvas_div);n”, ” this.root.appendChild(canvas_div);n”, “n”, ” var canvas = (this.canvas = document.createElement(‘canvas’));n”, ” canvas.classList.add(‘mpl-canvas’);n”, ” canvas.setAttribute(‘style’, ‘box-sizing: content-box;’);n”, “n”, ” this.context = canvas.getContext(‘2d’);n”, “n”, ” var backingStore =n”, ” this.context.backingStorePixelRatio ||n”, ” this.context.webkitBackingStorePixelRatio ||n”, ” this.context.mozBackingStorePixelRatio ||n”, ” this.context.msBackingStorePixelRatio ||n”, ” this.context.oBackingStorePixelRatio ||n”, ” this.context.backingStorePixelRatio ||n”, ” 1;n”, “n”, ” this.ratio = (window.devicePixelRatio || 1) / backingStore;n”, ” if (this.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: this.ratio });n”, ” }n”, “n”, ” var rubberband_canvas = (this.rubberband_canvas = document.createElement(n”, ” ‘canvas’n”, ” ));n”, ” rubberband_canvas.setAttribute(n”, ” ‘style’,n”, ” ‘box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;’n”, ” );n”, “n”,
- <<<<<<< HEAD
” // Apply a ponyfill if ResizeObserver is not implemented by browser.n”, ” if (this.ResizeObserver === undefined) {n”, ” if (window.ResizeObserver !== undefined) {n”, ” this.ResizeObserver = window.ResizeObserver;n”, ” } else {n”, ” var obs = _JSXTOOLS_RESIZE_OBSERVER({});n”, ” this.ResizeObserver = obs.ResizeObserver;n”, ” }n”, ” }n”, “n”, ” this.resizeObserverInstance = new this.ResizeObserver(function (entries) {n”,
” var nentries = entries.length;n”, ” for (var i = 0; i < nentries; i++) {n”, ” var entry = entries[i];n”, ” var width, height;n”, ” if (entry.contentBoxSize) {n”, ” if (entry.contentBoxSize instanceof Array) {n”, ” // Chrome 84 implements new version of spec.n”, ” width = entry.contentBoxSize[0].inlineSize;n”, ” height = entry.contentBoxSize[0].blockSize;n”, ” } else {n”, ” // Firefox implements old version of spec.n”, ” width = entry.contentBoxSize.inlineSize;n”, ” height = entry.contentBoxSize.blockSize;n”, ” }n”, ” } else {n”, ” // Chrome <84 implements even older version of spec.n”, ” width = entry.contentRect.width;n”, ” height = entry.contentRect.height;n”, ” }n”, “n”, ” // Keep the size of the canvas and rubber band canvas in sync withn”, ” // the canvas container.n”, ” if (entry.devicePixelContentBoxSize) {n”, ” // Chrome 84 implements new version of spec.n”, ” canvas.setAttribute(n”, ” ‘width’,n”, ” entry.devicePixelContentBoxSize[0].inlineSizen”, ” );n”, ” canvas.setAttribute(n”, ” ‘height’,n”, ” entry.devicePixelContentBoxSize[0].blockSizen”, ” );n”, ” } else {n”, ” canvas.setAttribute(‘width’, width * fig.ratio);n”, ” canvas.setAttribute(‘height’, height * fig.ratio);n”, ” }n”, ” canvas.setAttribute(n”, ” ‘style’,n”, ” ‘width: ‘ + width + ‘px; height: ‘ + height + ‘px;’n”, ” );n”, “n”, ” rubberband_canvas.setAttribute(‘width’, width);n”, ” rubberband_canvas.setAttribute(‘height’, height);n”, “n”, ” // And update the size in Python. We ignore the initial 0/0 sizen”, ” // that occurs as the element is placed into the DOM, which shouldn”, ” // otherwise not happen due to the minimum size styling.n”, ” if (width != 0 && height != 0) {n”, ” fig.request_resize(width, height);n”, ” }n”, ” }n”, ” });n”,
- <<<<<<< HEAD
” this.resizeObserverInstance.observe(canvas_div);n”,
“n”, ” function on_mouse_event_closure(name) {n”, ” return function (event) {n”, ” return fig.mouse_event(event, name);n”, ” };n”, ” }n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousedown’,n”, ” on_mouse_event_closure(‘button_press’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseup’,n”, ” on_mouse_event_closure(‘button_release’)n”, ” );n”, ” // Throttle sequential mouse events to 1 every 20ms.n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousemove’,n”, ” on_mouse_event_closure(‘motion_notify’)n”, ” );n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseenter’,n”, ” on_mouse_event_closure(‘figure_enter’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseleave’,n”, ” on_mouse_event_closure(‘figure_leave’)n”, ” );n”, “n”, ” canvas_div.addEventListener(‘wheel’, function (event) {n”, ” if (event.deltaY < 0) {n”, ” event.step = 1;n”, ” } else {n”, ” event.step = -1;n”, ” }n”, ” on_mouse_event_closure(‘scroll’)(event);n”, ” });n”, “n”, ” canvas_div.appendChild(canvas);n”, ” canvas_div.appendChild(rubberband_canvas);n”, “n”, ” this.rubberband_context = rubberband_canvas.getContext(‘2d’);n”, ” this.rubberband_context.strokeStyle = ‘#000000’;n”, “n”, ” this._resize_canvas = function (width, height, forward) {n”, ” if (forward) {n”, ” canvas_div.style.width = width + ‘px’;n”, ” canvas_div.style.height = height + ‘px’;n”, ” }n”, ” };n”, “n”, ” // Disable right mouse context menu.n”, ” this.rubberband_canvas.addEventListener(‘contextmenu’, function (_e) {n”, ” event.preventDefault();n”, ” return false;n”, ” });n”, “n”, ” function set_focus() {n”, ” canvas.focus();n”, ” canvas_div.focus();n”, ” }n”, “n”, ” window.setTimeout(set_focus, 100);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘mpl-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. /n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” continue;n”, ” }n”, “n”, ” var button = (fig.buttons[name] = document.createElement(‘button’));n”, ” button.classList = ‘mpl-widget’;n”, ” button.setAttribute(‘role’, ‘button’);n”, ” button.setAttribute(‘aria-disabled’, ‘false’);n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, “n”, ” var icon_img = document.createElement(‘img’);n”, ” icon_img.src = ‘_images/’ + image + ‘.png’;n”, ” icon_img.srcset = ‘_images/’ + image + ‘_large.png 2x’;n”, ” icon_img.alt = tooltip;n”, ” button.appendChild(icon_img);n”, “n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” var fmt_picker = document.createElement(‘select’);n”, ” fmt_picker.classList = ‘mpl-widget’;n”, ” toolbar.appendChild(fmt_picker);n”, ” this.format_dropdown = fmt_picker;n”, “n”, ” for (var ind in mpl.extensions) {n”, ” var fmt = mpl.extensions[ind];n”, ” var option = document.createElement(‘option’);n”, ” option.selected = fmt === mpl.default_extension;n”, ” option.innerHTML = fmt;n”, ” fmt_picker.appendChild(option);n”, ” }n”, “n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “};n”, “n”, “mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {n”, ” // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,n”, ” // which will in turn request a refresh of the image.n”, ” this.send_message(‘resize’, { width: x_pixels, height: y_pixels });n”, “};n”, “n”, “mpl.figure.prototype.send_message = function (type, properties) {n”, ” properties[‘type’] = type;n”, ” properties[‘figure_id’] = this.id;n”, ” this.ws.send(JSON.stringify(properties));n”, “};n”, “n”, “mpl.figure.prototype.send_draw_message = function () {n”, ” if (!this.waiting) {n”, ” this.waiting = true;n”, ” this.ws.send(JSON.stringify({ type: ‘draw’, figure_id: this.id }));n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” var format_dropdown = fig.format_dropdown;n”, ” var format = format_dropdown.options[format_dropdown.selectedIndex].value;n”, ” fig.ondownload(fig, format);n”, “};n”, “n”, “mpl.figure.prototype.handle_resize = function (fig, msg) {n”, ” var size = msg[‘size’];n”, ” if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {n”, ” fig._resize_canvas(size[0], size[1], msg[‘forward’]);n”, ” fig.send_message(‘refresh’, {});n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_rubberband = function (fig, msg) {n”, ” var x0 = msg[‘x0’] / fig.ratio;n”, ” var y0 = (fig.canvas.height - msg[‘y0’]) / fig.ratio;n”, ” var x1 = msg[‘x1’] / fig.ratio;n”, ” var y1 = (fig.canvas.height - msg[‘y1’]) / fig.ratio;n”, ” x0 = Math.floor(x0) + 0.5;n”, ” y0 = Math.floor(y0) + 0.5;n”, ” x1 = Math.floor(x1) + 0.5;n”, ” y1 = Math.floor(y1) + 0.5;n”, ” var min_x = Math.min(x0, x1);n”, ” var min_y = Math.min(y0, y1);n”, ” var width = Math.abs(x1 - x0);n”, ” var height = Math.abs(y1 - y0);n”, “n”, ” fig.rubberband_context.clearRect(n”, ” 0,n”, ” 0,n”, ” fig.canvas.width / fig.ratio,n”, ” fig.canvas.height / fig.ration”, ” );n”, “n”, ” fig.rubberband_context.strokeRect(min_x, min_y, width, height);n”, “};n”, “n”, “mpl.figure.prototype.handle_figure_label = function (fig, msg) {n”, ” // Updates the figure title.n”, ” fig.header.textContent = msg[‘label’];n”, “};n”, “n”, “mpl.figure.prototype.handle_cursor = function (fig, msg) {n”, ” var cursor = msg[‘cursor’];n”, ” switch (cursor) {n”, ” case 0:n”, ” cursor = ‘pointer’;n”, ” break;n”, ” case 1:n”, ” cursor = ‘default’;n”, ” break;n”, ” case 2:n”, ” cursor = ‘crosshair’;n”, ” break;n”, ” case 3:n”, ” cursor = ‘move’;n”, ” break;n”, ” }n”, ” fig.rubberband_canvas.style.cursor = cursor;n”, “};n”, “n”, “mpl.figure.prototype.handle_message = function (fig, msg) {n”, ” fig.message.textContent = msg[‘message’];n”, “};n”, “n”, “mpl.figure.prototype.handle_draw = function (fig, _msg) {n”, ” // Request the server to send over a new figure.n”, ” fig.send_draw_message();n”, “};n”, “n”, “mpl.figure.prototype.handle_image_mode = function (fig, msg) {n”, ” fig.image_mode = msg[‘mode’];n”, “};n”, “n”, “mpl.figure.prototype.handle_history_buttons = function (fig, msg) {n”, ” for (var key in msg) {n”, ” if (!(key in fig.buttons)) {n”, ” continue;n”, ” }n”, ” fig.buttons[key].disabled = !msg[key];n”, ” fig.buttons[key].setAttribute(‘aria-disabled’, !msg[key]);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {n”, ” if (msg[‘mode’] === ‘PAN’) {n”, ” fig.buttons[‘Pan’].classList.add(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” } else if (msg[‘mode’] === ‘ZOOM’) {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.add(‘active’);n”, ” } else {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Called whenever the canvas gets updated.n”, ” this.send_message(‘ack’, {});n”, “};n”, “n”, “// A function to construct a web socket function for onmessage handling.n”, “// Called in the figure constructor.n”, “mpl.figure.prototype._make_on_message_function = function (fig) {n”, ” return function socket_on_message(evt) {n”, ” if (evt.data instanceof Blob) {n”, ” / FIXME: We get "Resource interpreted as Image butn”, ” * transferred with MIME type text/plain:" errors onn”, ” * Chrome. But how to set the MIME type? It doesn’t seemn”, ” * to be part of the websocket stream /n”, ” evt.data.type = ‘image/png’;n”, “n”, ” / Free the memory for the previous frames /n”, ” if (fig.imageObj.src) {n”, ” (window.URL || window.webkitURL).revokeObjectURL(n”, ” fig.imageObj.srcn”, ” );n”, ” }n”, “n”, ” fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(n”, ” evt.datan”, ” );n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” } else if (n”, ” typeof evt.data === ‘string’ &&n”, ” evt.data.slice(0, 21) === ‘data:image/png;base64’n”, ” ) {n”, ” fig.imageObj.src = evt.data;n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” }n”, “n”, ” var msg = JSON.parse(evt.data);n”, ” var msg_type = msg[‘type’];n”, “n”, ” // Call the "handle_{type}" callback, which takesn”, ” // the figure and JSON message as its only arguments.n”, ” try {n”, ” var callback = fig[‘handle_’ + msg_type];n”, ” } catch (e) {n”, ” console.log(n”, ” "No handler for the ‘" + msg_type + "’ message type: ",n”, ” msgn”, ” );n”, ” return;n”, ” }n”, “n”, ” if (callback) {n”, ” try {n”, ” // console.log("Handling ‘" + msg_type + "’ message: ", msg);n”, ” callback(fig, msg);n”, ” } catch (e) {n”, ” console.log(n”, ” "Exception inside the ‘handler_" + msg_type + "’ callback:",n”, ” e,n”, ” e.stack,n”, ” msgn”, ” );n”, ” }n”, ” }n”, ” };n”, “};n”, “n”, “// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvasn”, “mpl.findpos = function (e) {n”, ” //this section is from http://www.quirksmode.org/js/events_properties.htmln”, ” var targ;n”, ” if (!e) {n”, ” e = window.event;n”, ” }n”, ” if (e.target) {n”, ” targ = e.target;n”, ” } else if (e.srcElement) {n”, ” targ = e.srcElement;n”, ” }n”, ” if (targ.nodeType === 3) {n”, ” // defeat Safari bugn”, ” targ = targ.parentNode;n”, ” }n”, “n”, ” // pageX,Y are the mouse positions relative to the documentn”, ” var boundingRect = targ.getBoundingClientRect();n”, ” var x = e.pageX - (boundingRect.left + document.body.scrollLeft);n”, ” var y = e.pageY - (boundingRect.top + document.body.scrollTop);n”, “n”, ” return { x: x, y: y };n”, “};n”, “n”, “/n”, ” * return a copy of an object with only non-object keysn”, ” * we need this to avoid circular referencesn”, ” * http://stackoverflow.com/a/24161582/3208463n”, ” /n”, “function simpleKeys(original) {n”, ” return Object.keys(original).reduce(function (obj, key) {n”, ” if (typeof original[key] !== ‘object’) {n”, ” obj[key] = original[key];n”, ” }n”, ” return obj;n”, ” }, {});n”, “}n”, “n”, “mpl.figure.prototype.mouse_event = function (event, name) {n”, ” var canvas_pos = mpl.findpos(event);n”, “n”, ” if (name === ‘button_press’) {n”, ” this.canvas.focus();n”, ” this.canvas_div.focus();n”, ” }n”, “n”, ” var x = canvas_pos.x * this.ratio;n”, ” var y = canvas_pos.y * this.ratio;n”, “n”, ” this.send_message(name, {n”, ” x: x,n”, ” y: y,n”, ” button: event.button,n”, ” step: event.step,n”, ” guiEvent: simpleKeys(event),n”, ” });n”, “n”, ” / This prevents the web browser from automatically changing ton”, ” * the text insertion cursor when the button is pressed. We wantn”, ” * to control all of the cursor setting manually through then”, ” * ‘cursor’ event from matplotlib */n”, ” event.preventDefault();n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (_event, _name) {n”, ” // Handle any extra behaviour associated with a key eventn”, “};n”, “n”, “mpl.figure.prototype.key_event = function (event, name) {n”, ” // Prevent repeat eventsn”, ” if (name === ‘key_press’) {n”, ” if (event.which === this._key) {n”, ” return;n”, ” } else {n”, ” this._key = event.which;n”, ” }n”, ” }n”, ” if (name === ‘key_release’) {n”, ” this._key = null;n”, ” }n”, “n”, ” var value = ‘’;n”, ” if (event.ctrlKey && event.which !== 17) {n”, ” value += ‘ctrl+’;n”, ” }n”, ” if (event.altKey && event.which !== 18) {n”, ” value += ‘alt+’;n”, ” }n”, ” if (event.shiftKey && event.which !== 16) {n”, ” value += ‘shift+’;n”, ” }n”, “n”, ” value += ‘k’;n”, ” value += event.which.toString();n”, “n”, ” this._key_event_extra(event, name);n”, “n”, ” this.send_message(name, { key: value, guiEvent: simpleKeys(event) });n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onclick = function (name) {n”, ” if (name === ‘download’) {n”, ” this.handle_save(this, null);n”, ” } else {n”, ” this.send_message(‘toolbar_button’, { name: name });n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {n”, ” this.message.textContent = tooltip;n”, “};n”,
- <<<<<<< HEAD
“n”, “///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////n”, “// prettier-ignoren”, “var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError("Constructor requires ‘new’ operator");i.set(this,e)}function h(){throw new TypeError("Function is not a constructor")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-linen”,
“n”, “mpl.extensions = ["eps", "jpeg", "pdf", "png", "ps", "raw", "svg", "tif"];n”, “n”, “mpl.default_extension = "png";/* global mpl */n”, “n”, “var comm_websocket_adapter = function (comm) {n”, ” // Create a "websocket"-like object which calls the given IPython commn”, ” // object with the appropriate methods. Currently this is a non binaryn”, ” // socket, so there is still some room for performance tuning.n”, ” var ws = {};n”, “n”, ” ws.close = function () {n”, ” comm.close();n”, ” };n”, ” ws.send = function (m) {n”, ” //console.log(‘sending’, m);n”, ” comm.send(m);n”, ” };n”, ” // Register the callback with on_msg.n”, ” comm.on_msg(function (msg) {n”, ” //console.log(‘receiving’, msg[‘content’][‘data’], msg);n”, ” // Pass the mpl event to the overridden (by mpl) onmessage function.n”, ” ws.onmessage(msg[‘content’][‘data’]);n”, ” });n”, ” return ws;n”, “};n”, “n”, “mpl.mpl_figure_comm = function (comm, msg) {n”, ” // This is the function which gets called when the mpl processn”, ” // starts-up an IPython Comm through the "matplotlib" channel.n”, “n”, ” var id = msg.content.data.id;n”, ” // Get hold of the div created by the display call when the Commn”, ” // socket was opened in Python.n”, ” var element = document.getElementById(id);n”, ” var ws_proxy = comm_websocket_adapter(comm);n”, “n”, ” function ondownload(figure, _format) {n”, ” window.open(figure.canvas.toDataURL());n”, ” }n”, “n”, ” var fig = new mpl.figure(id, ws_proxy, ondownload, element);n”, “n”, ” // Call onopen now - mpl needs it, as it is assuming we’ve passed it a realn”, ” // web socket which is closed, not our websocket->open comm proxy.n”, ” ws_proxy.onopen();n”, “n”, ” fig.parent_element = element;n”, ” fig.cell_info = mpl.find_output_cell("<div id=’" + id + "’></div>");n”, ” if (!fig.cell_info) {n”, ” console.error(‘Failed to find cell for figure’, id, fig);n”, ” return;n”, ” }n”,
- <<<<<<< HEAD
” fig.cell_info[0].output_area.element.on(n”,
” ‘cleared’,n”, ” { fig: fig },n”, ” fig._remove_fig_handlern”, ” );n”, “};n”, “n”, “mpl.figure.prototype.handle_close = function (fig, msg) {n”, ” var width = fig.canvas.width / fig.ratio;n”, ” fig.cell_info[0].output_area.element.off(n”, ” ‘cleared’,n”, ” fig._remove_fig_handlern”, ” );n”,
- <<<<<<< HEAD
” fig.resizeObserverInstance.unobserve(fig.canvas_div);n”,
” // Update the output cell to use the data from the current canvas.n”, ” fig.push_to_output();n”, ” var dataURL = fig.canvas.toDataURL();n”, ” // Re-enable the keyboard manager in IPython - without this line, in FF,n”, ” // the notebook keyboard shortcuts fail.n”, ” IPython.keyboard_manager.enable();n”, ” fig.parent_element.innerHTML =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, ” fig.close_ws(fig, msg);n”, “};n”, “n”, “mpl.figure.prototype.close_ws = function (fig, msg) {n”, ” fig.send_message(‘closing’, msg);n”, ” // fig.ws.close()n”, “};n”, “n”, “mpl.figure.prototype.push_to_output = function (_remove_interactive) {n”, ” // Turn the data on the canvas into data in the output cell.n”, ” var width = this.canvas.width / this.ratio;n”, ” var dataURL = this.canvas.toDataURL();n”, ” this.cell_info[1][‘text/html’] =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Tell IPython that the notebook contents must change.n”, ” IPython.notebook.set_dirty(true);n”, ” this.send_message(‘ack’, {});n”, ” var fig = this;n”, ” // Wait a second, then push the new image to the DOM son”, ” // that it is saved nicely (might be nice to debounce this).n”, ” setTimeout(function () {n”, ” fig.push_to_output();n”, ” }, 1000);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘btn-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” var button;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. */n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” continue;n”, ” }n”, “n”, ” button = fig.buttons[name] = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-default’;n”, ” button.href = ‘#’;n”, ” button.title = name;n”, ” button.innerHTML = ‘<i class="fa ‘ + image + ‘ fa-lg"></i>’;n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” // Add the status bar.n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message pull-right’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “n”, ” // Add the close button to the window.n”, ” var buttongrp = document.createElement(‘div’);n”, ” buttongrp.classList = ‘btn-group inline pull-right’;n”, ” button = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-mini btn-primary’;n”, ” button.href = ‘#’;n”, ” button.title = ‘Stop Interaction’;n”, ” button.innerHTML = ‘<i class="fa fa-power-off icon-remove icon-large"></i>’;n”, ” button.addEventListener(‘click’, function (_evt) {n”, ” fig.handle_close(fig, {});n”, ” });n”, ” button.addEventListener(n”, ” ‘mouseover’,n”, ” on_mouseover_closure(‘Stop Interaction’)n”, ” );n”, ” buttongrp.appendChild(button);n”, ” var titlebar = this.root.querySelector(‘.ui-dialog-titlebar’);n”, ” titlebar.insertBefore(buttongrp, titlebar.firstChild);n”, “};n”, “n”, “mpl.figure.prototype._remove_fig_handler = function (event) {n”, ” var fig = event.data.fig;n”,
- <<<<<<< HEAD
” if (event.target !== this) {n”, ” // Ignore bubbled events from children.n”, ” return;n”, ” }n”,
“};n”, “n”, “mpl.figure.prototype._root_extra_style = function (el) {n”, ” el.style.boxSizing = ‘content-box’; // override notebook setting of border-box.n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (el) {n”, ” // this is important to make the div ‘focusablen”, ” el.setAttribute(‘tabindex’, 0);n”, ” // reach out to IPython and tell the keyboard manager to turn it’s selfn”, ” // off when our div gets focusn”, “n”, ” // location in version 3n”, ” if (IPython.notebook.keyboard_manager) {n”, ” IPython.notebook.keyboard_manager.register_events(el);n”, ” } else {n”, ” // location in version 2n”, ” IPython.keyboard_manager.register_events(el);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (event, _name) {n”, ” var manager = IPython.notebook.keyboard_manager;n”, ” if (!manager) {n”, ” manager = IPython.keyboard_manager;n”, ” }n”, “n”, ” // Check for shift+entern”, ” if (event.shiftKey && event.which === 13) {n”, ” this.canvas_div.blur();n”, ” // select the cell after this onen”, ” var index = IPython.notebook.find_cell_index(this.cell_info[0]);n”, ” IPython.notebook.select(index + 1);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” fig.ondownload(fig, null);n”, “};n”, “n”, “mpl.find_output_cell = function (html_output) {n”, ” // Return the cell and output element which can be found uniquely in the notebook.n”, ” // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"n”, ” // IPython event is triggered only after the cells have been serialised, which forn”, ” // our purposes (turning an active figure into a static one), is too late.n”, ” var cells = IPython.notebook.get_cells();n”, ” var ncells = cells.length;n”, ” for (var i = 0; i < ncells; i++) {n”, ” var cell = cells[i];n”, ” if (cell.cell_type === ‘code’) {n”, ” for (var j = 0; j < cell.output_area.outputs.length; j++) {n”, ” var data = cell.output_area.outputs[j];n”, ” if (data.data) {n”, ” // IPython >= 3 moved mimebundle to data attribute of outputn”, ” data = data.data;n”, ” }n”, ” if (data[‘text/html’] === html_output) {n”, ” return [cell, data, j];n”, ” }n”, ” }n”, ” }n”, ” }n”, “};n”, “n”, “// Register the function which deals with the matplotlib target/channel.n”, “// The kernel may be null if the page has been refreshed.n”, “if (IPython.notebook.kernel !== null) {n”, ” IPython.notebook.kernel.comm_manager.register_target(n”, ” ‘matplotlib’,n”, ” mpl.mpl_figure_commn”, ” );n”, “}n”
], “text/plain”: [
“<IPython.core.display.Javascript object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/html”: [
], “text/plain”: [
“<IPython.core.display.HTML object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}
], “source”: [
“from matplotlib.widgets import EllipseSelectorn”, “n”, “print(np.array(center)-2048)n”, “center = np.array(center)n”, “#center[0] = XCentern”, “#center[1] = YCentern”, “n”, “plt.figure(figsize=(8, 6))n”, “plt.imshow(np.log(1.+diff_pattern).T, origin = ‘upper’)n”, “selector = EllipseSelector(plt.gca(), None,interactive=True , drawtype=’box’) # gca get current axis (plot)n”, “n”, “selector.to_draw.set_visible(True)n”, “radius = 559 n”, “center = np.array(center)n”, “n”, “selector.extents = (center[0]-radius,center[0]+radius,center[1]-radius,center[1]+radius)n”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“Get center coordinates from selection”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 6,
- “metadata”: {
“scrolled”: true
}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“radius = 559 pixelsn”,
- <<<<<<< HEAD
“new center = (1090.0, 1182.0) [pixels]n”
]
}
], “source”: [
“xmin, xmax, ymin, ymax = selector.extentsn”, “x_center, y_center = selector.centern”, “x_shift = x_center - diff_pattern.shape[0]/2n”, “y_shift = y_center - diff_pattern.shape[1]/2n”, “print(f’radius = {(xmax-xmin)/2:.0f} pixels’)n”, “n”, “center = (x_center, y_center )n”, “print(f’new center = {center} [pixels]’)n”, “n”, “out_tags ={}n”, “out_tags[‘center’] = center”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Ploting Diffraction Pattern in Polar Coordinatesn”, “n”, “### The Transformation Routine”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 7,
“metadata”: {}, “outputs”: [], “source”: [
“from scipy.interpolate import interp1dn”, “from scipy.ndimage import map_coordinatesn”, “n”, “n”, “def cartesian2polar(x, y, grid, r, t, order=3):n”, “n”, ” R,T = np.meshgrid(r, t)n”, “n”, ” new_x = R*np.cos(T)n”, ” new_y = R*np.sin(T)n”, “n”, ” ix = interp1d(x, np.arange(len(x)))n”, ” iy = interp1d(y, np.arange(len(y)))n”, “n”, ” new_ix = ix(new_x.ravel())n”, ” new_iy = iy(new_y.ravel())n”, “n”, ” n”, ” return map_coordinates(grid, np.array([new_ix, new_iy]),n”, ” order=order).reshape(new_x.shape)n”, “n”, “def warp(diff,center):n”, ” # Define original polar gridn”, ” nx = diff.shape[0]n”, ” ny = diff.shape[1]n”, “n”, ” x = np.linspace(1, nx, nx, endpoint = True)-center[0]n”, ” y = np.linspace(1, ny, ny, endpoint = True)-center[1]n”, ” z = diffn”, “n”, ” # Define new polar gridn”, ” nr = int(min([center[0], center[1], diff.shape[0]-center[0], diff.shape[1]-center[1]])-1)n”, ” print(nr)n”, ” nt = 360*3n”, “n”, “n”, ” r = np.linspace(1, nr, nr)n”, ” t = np.linspace(0., np.pi, nt, endpoint = False)n”, ” return cartesian2polar(x,y, z, r, t, order=3).T”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“### Now we transformn”, “n”, “If the center is correct a ring in carthesian coordinates is a line in polar coordinatesn”, “n”, “A simple sum over all angles gives us then the diffraction profile (intensity profile of diffraction pattern)”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 8,
“metadata”: {}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
- <<<<<<< HEAD
“865n”
]
}, {
- “data”: {
- “application/javascript”: [
“/* Put everything inside the global mpl namespace /n”, “/ global mpl */n”, “window.mpl = {};n”, “n”, “mpl.get_websocket_type = function () {n”, ” if (typeof WebSocket !== ‘undefined’) {n”, ” return WebSocket;n”, ” } else if (typeof MozWebSocket !== ‘undefined’) {n”, ” return MozWebSocket;n”, ” } else {n”, ” alert(n”, ” ‘Your browser does not have WebSocket support. ‘ +n”, ” ‘Please try Chrome, Safari or Firefox ≥ 6. ‘ +n”, ” ‘Firefox 4 and 5 are also supported but you ‘ +n”, ” ‘have to enable WebSockets in about:config.’n”, ” );n”, ” }n”, “};n”, “n”, “mpl.figure = function (figure_id, websocket, ondownload, parent_element) {n”, ” this.id = figure_id;n”, “n”, ” this.ws = websocket;n”, “n”, ” this.supports_binary = this.ws.binaryType !== undefined;n”, “n”, ” if (!this.supports_binary) {n”, ” var warnings = document.getElementById(‘mpl-warnings’);n”, ” if (warnings) {n”, ” warnings.style.display = ‘block’;n”, ” warnings.textContent =n”, ” ‘This browser does not support binary websocket messages. ‘ +n”, ” ‘Performance may be slow.’;n”, ” }n”, ” }n”, “n”, ” this.imageObj = new Image();n”, “n”, ” this.context = undefined;n”, ” this.message = undefined;n”, ” this.canvas = undefined;n”, ” this.rubberband_canvas = undefined;n”, ” this.rubberband_context = undefined;n”, ” this.format_dropdown = undefined;n”, “n”, ” this.image_mode = ‘full’;n”, “n”, ” this.root = document.createElement(‘div’);n”, ” this.root.setAttribute(‘style’, ‘display: inline-block’);n”, ” this._root_extra_style(this.root);n”, “n”, ” parent_element.appendChild(this.root);n”, “n”, ” this._init_header(this);n”, ” this._init_canvas(this);n”, ” this._init_toolbar(this);n”, “n”, ” var fig = this;n”, “n”, ” this.waiting = false;n”, “n”, ” this.ws.onopen = function () {n”, ” fig.send_message(‘supports_binary’, { value: fig.supports_binary });n”, ” fig.send_message(‘send_image_mode’, {});n”, ” if (fig.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: fig.ratio });n”, ” }n”, ” fig.send_message(‘refresh’, {});n”, ” };n”, “n”, ” this.imageObj.onload = function () {n”, ” if (fig.image_mode === ‘full’) {n”, ” // Full images could contain transparency (where diff imagesn”, ” // almost always do), so we need to clear the canvas so thatn”, ” // there is no ghosting.n”, ” fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);n”, ” }n”, ” fig.context.drawImage(fig.imageObj, 0, 0);n”, ” };n”, “n”, ” this.imageObj.onunload = function () {n”, ” fig.ws.close();n”, ” };n”, “n”, ” this.ws.onmessage = this._make_on_message_function(this);n”, “n”, ” this.ondownload = ondownload;n”, “};n”, “n”, “mpl.figure.prototype._init_header = function () {n”, ” var titlebar = document.createElement(‘div’);n”, ” titlebar.classList =n”, ” ‘ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix’;n”, ” var titletext = document.createElement(‘div’);n”, ” titletext.classList = ‘ui-dialog-title’;n”, ” titletext.setAttribute(n”, ” ‘style’,n”, ” ‘width: 100%; text-align: center; padding: 3px;’n”, ” );n”, ” titlebar.appendChild(titletext);n”, ” this.root.appendChild(titlebar);n”, ” this.header = titletext;n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._root_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._init_canvas = function () {n”, ” var fig = this;n”, “n”, ” var canvas_div = (this.canvas_div = document.createElement(‘div’));n”, ” canvas_div.setAttribute(n”, ” ‘style’,n”, ” ‘border: 1px solid #ddd;’ +n”, ” ‘box-sizing: content-box;’ +n”, ” ‘clear: both;’ +n”, ” ‘min-height: 1px;’ +n”, ” ‘min-width: 1px;’ +n”, ” ‘outline: 0;’ +n”, ” ‘overflow: hidden;’ +n”, ” ‘position: relative;’ +n”, ” ‘resize: both;’n”, ” );n”, “n”, ” function on_keyboard_event_closure(name) {n”, ” return function (event) {n”, ” return fig.key_event(event, name);n”, ” };n”, ” }n”, “n”, ” canvas_div.addEventListener(n”, ” ‘keydown’,n”, ” on_keyboard_event_closure(‘key_press’)n”, ” );n”, ” canvas_div.addEventListener(n”, ” ‘keyup’,n”, ” on_keyboard_event_closure(‘key_release’)n”, ” );n”, “n”, ” this._canvas_extra_style(canvas_div);n”, ” this.root.appendChild(canvas_div);n”, “n”, ” var canvas = (this.canvas = document.createElement(‘canvas’));n”, ” canvas.classList.add(‘mpl-canvas’);n”, ” canvas.setAttribute(‘style’, ‘box-sizing: content-box;’);n”, “n”, ” this.context = canvas.getContext(‘2d’);n”, “n”, ” var backingStore =n”, ” this.context.backingStorePixelRatio ||n”, ” this.context.webkitBackingStorePixelRatio ||n”, ” this.context.mozBackingStorePixelRatio ||n”, ” this.context.msBackingStorePixelRatio ||n”, ” this.context.oBackingStorePixelRatio ||n”, ” this.context.backingStorePixelRatio ||n”, ” 1;n”, “n”, ” this.ratio = (window.devicePixelRatio || 1) / backingStore;n”, ” if (this.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: this.ratio });n”, ” }n”, “n”, ” var rubberband_canvas = (this.rubberband_canvas = document.createElement(n”, ” ‘canvas’n”, ” ));n”, ” rubberband_canvas.setAttribute(n”, ” ‘style’,n”, ” ‘box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;’n”, ” );n”, “n”,
- <<<<<<< HEAD
” // Apply a ponyfill if ResizeObserver is not implemented by browser.n”, ” if (this.ResizeObserver === undefined) {n”, ” if (window.ResizeObserver !== undefined) {n”, ” this.ResizeObserver = window.ResizeObserver;n”, ” } else {n”, ” var obs = _JSXTOOLS_RESIZE_OBSERVER({});n”, ” this.ResizeObserver = obs.ResizeObserver;n”, ” }n”, ” }n”, “n”, ” this.resizeObserverInstance = new this.ResizeObserver(function (entries) {n”,
” var nentries = entries.length;n”, ” for (var i = 0; i < nentries; i++) {n”, ” var entry = entries[i];n”, ” var width, height;n”, ” if (entry.contentBoxSize) {n”, ” if (entry.contentBoxSize instanceof Array) {n”, ” // Chrome 84 implements new version of spec.n”, ” width = entry.contentBoxSize[0].inlineSize;n”, ” height = entry.contentBoxSize[0].blockSize;n”, ” } else {n”, ” // Firefox implements old version of spec.n”, ” width = entry.contentBoxSize.inlineSize;n”, ” height = entry.contentBoxSize.blockSize;n”, ” }n”, ” } else {n”, ” // Chrome <84 implements even older version of spec.n”, ” width = entry.contentRect.width;n”, ” height = entry.contentRect.height;n”, ” }n”, “n”, ” // Keep the size of the canvas and rubber band canvas in sync withn”, ” // the canvas container.n”, ” if (entry.devicePixelContentBoxSize) {n”, ” // Chrome 84 implements new version of spec.n”, ” canvas.setAttribute(n”, ” ‘width’,n”, ” entry.devicePixelContentBoxSize[0].inlineSizen”, ” );n”, ” canvas.setAttribute(n”, ” ‘height’,n”, ” entry.devicePixelContentBoxSize[0].blockSizen”, ” );n”, ” } else {n”, ” canvas.setAttribute(‘width’, width * fig.ratio);n”, ” canvas.setAttribute(‘height’, height * fig.ratio);n”, ” }n”, ” canvas.setAttribute(n”, ” ‘style’,n”, ” ‘width: ‘ + width + ‘px; height: ‘ + height + ‘px;’n”, ” );n”, “n”, ” rubberband_canvas.setAttribute(‘width’, width);n”, ” rubberband_canvas.setAttribute(‘height’, height);n”, “n”, ” // And update the size in Python. We ignore the initial 0/0 sizen”, ” // that occurs as the element is placed into the DOM, which shouldn”, ” // otherwise not happen due to the minimum size styling.n”, ” if (width != 0 && height != 0) {n”, ” fig.request_resize(width, height);n”, ” }n”, ” }n”, ” });n”,
- <<<<<<< HEAD
” this.resizeObserverInstance.observe(canvas_div);n”,
“n”, ” function on_mouse_event_closure(name) {n”, ” return function (event) {n”, ” return fig.mouse_event(event, name);n”, ” };n”, ” }n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousedown’,n”, ” on_mouse_event_closure(‘button_press’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseup’,n”, ” on_mouse_event_closure(‘button_release’)n”, ” );n”, ” // Throttle sequential mouse events to 1 every 20ms.n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousemove’,n”, ” on_mouse_event_closure(‘motion_notify’)n”, ” );n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseenter’,n”, ” on_mouse_event_closure(‘figure_enter’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseleave’,n”, ” on_mouse_event_closure(‘figure_leave’)n”, ” );n”, “n”, ” canvas_div.addEventListener(‘wheel’, function (event) {n”, ” if (event.deltaY < 0) {n”, ” event.step = 1;n”, ” } else {n”, ” event.step = -1;n”, ” }n”, ” on_mouse_event_closure(‘scroll’)(event);n”, ” });n”, “n”, ” canvas_div.appendChild(canvas);n”, ” canvas_div.appendChild(rubberband_canvas);n”, “n”, ” this.rubberband_context = rubberband_canvas.getContext(‘2d’);n”, ” this.rubberband_context.strokeStyle = ‘#000000’;n”, “n”, ” this._resize_canvas = function (width, height, forward) {n”, ” if (forward) {n”, ” canvas_div.style.width = width + ‘px’;n”, ” canvas_div.style.height = height + ‘px’;n”, ” }n”, ” };n”, “n”, ” // Disable right mouse context menu.n”, ” this.rubberband_canvas.addEventListener(‘contextmenu’, function (_e) {n”, ” event.preventDefault();n”, ” return false;n”, ” });n”, “n”, ” function set_focus() {n”, ” canvas.focus();n”, ” canvas_div.focus();n”, ” }n”, “n”, ” window.setTimeout(set_focus, 100);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘mpl-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. /n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” continue;n”, ” }n”, “n”, ” var button = (fig.buttons[name] = document.createElement(‘button’));n”, ” button.classList = ‘mpl-widget’;n”, ” button.setAttribute(‘role’, ‘button’);n”, ” button.setAttribute(‘aria-disabled’, ‘false’);n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, “n”, ” var icon_img = document.createElement(‘img’);n”, ” icon_img.src = ‘_images/’ + image + ‘.png’;n”, ” icon_img.srcset = ‘_images/’ + image + ‘_large.png 2x’;n”, ” icon_img.alt = tooltip;n”, ” button.appendChild(icon_img);n”, “n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” var fmt_picker = document.createElement(‘select’);n”, ” fmt_picker.classList = ‘mpl-widget’;n”, ” toolbar.appendChild(fmt_picker);n”, ” this.format_dropdown = fmt_picker;n”, “n”, ” for (var ind in mpl.extensions) {n”, ” var fmt = mpl.extensions[ind];n”, ” var option = document.createElement(‘option’);n”, ” option.selected = fmt === mpl.default_extension;n”, ” option.innerHTML = fmt;n”, ” fmt_picker.appendChild(option);n”, ” }n”, “n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “};n”, “n”, “mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {n”, ” // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,n”, ” // which will in turn request a refresh of the image.n”, ” this.send_message(‘resize’, { width: x_pixels, height: y_pixels });n”, “};n”, “n”, “mpl.figure.prototype.send_message = function (type, properties) {n”, ” properties[‘type’] = type;n”, ” properties[‘figure_id’] = this.id;n”, ” this.ws.send(JSON.stringify(properties));n”, “};n”, “n”, “mpl.figure.prototype.send_draw_message = function () {n”, ” if (!this.waiting) {n”, ” this.waiting = true;n”, ” this.ws.send(JSON.stringify({ type: ‘draw’, figure_id: this.id }));n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” var format_dropdown = fig.format_dropdown;n”, ” var format = format_dropdown.options[format_dropdown.selectedIndex].value;n”, ” fig.ondownload(fig, format);n”, “};n”, “n”, “mpl.figure.prototype.handle_resize = function (fig, msg) {n”, ” var size = msg[‘size’];n”, ” if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {n”, ” fig._resize_canvas(size[0], size[1], msg[‘forward’]);n”, ” fig.send_message(‘refresh’, {});n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_rubberband = function (fig, msg) {n”, ” var x0 = msg[‘x0’] / fig.ratio;n”, ” var y0 = (fig.canvas.height - msg[‘y0’]) / fig.ratio;n”, ” var x1 = msg[‘x1’] / fig.ratio;n”, ” var y1 = (fig.canvas.height - msg[‘y1’]) / fig.ratio;n”, ” x0 = Math.floor(x0) + 0.5;n”, ” y0 = Math.floor(y0) + 0.5;n”, ” x1 = Math.floor(x1) + 0.5;n”, ” y1 = Math.floor(y1) + 0.5;n”, ” var min_x = Math.min(x0, x1);n”, ” var min_y = Math.min(y0, y1);n”, ” var width = Math.abs(x1 - x0);n”, ” var height = Math.abs(y1 - y0);n”, “n”, ” fig.rubberband_context.clearRect(n”, ” 0,n”, ” 0,n”, ” fig.canvas.width / fig.ratio,n”, ” fig.canvas.height / fig.ration”, ” );n”, “n”, ” fig.rubberband_context.strokeRect(min_x, min_y, width, height);n”, “};n”, “n”, “mpl.figure.prototype.handle_figure_label = function (fig, msg) {n”, ” // Updates the figure title.n”, ” fig.header.textContent = msg[‘label’];n”, “};n”, “n”, “mpl.figure.prototype.handle_cursor = function (fig, msg) {n”, ” var cursor = msg[‘cursor’];n”, ” switch (cursor) {n”, ” case 0:n”, ” cursor = ‘pointer’;n”, ” break;n”, ” case 1:n”, ” cursor = ‘default’;n”, ” break;n”, ” case 2:n”, ” cursor = ‘crosshair’;n”, ” break;n”, ” case 3:n”, ” cursor = ‘move’;n”, ” break;n”, ” }n”, ” fig.rubberband_canvas.style.cursor = cursor;n”, “};n”, “n”, “mpl.figure.prototype.handle_message = function (fig, msg) {n”, ” fig.message.textContent = msg[‘message’];n”, “};n”, “n”, “mpl.figure.prototype.handle_draw = function (fig, _msg) {n”, ” // Request the server to send over a new figure.n”, ” fig.send_draw_message();n”, “};n”, “n”, “mpl.figure.prototype.handle_image_mode = function (fig, msg) {n”, ” fig.image_mode = msg[‘mode’];n”, “};n”, “n”, “mpl.figure.prototype.handle_history_buttons = function (fig, msg) {n”, ” for (var key in msg) {n”, ” if (!(key in fig.buttons)) {n”, ” continue;n”, ” }n”, ” fig.buttons[key].disabled = !msg[key];n”, ” fig.buttons[key].setAttribute(‘aria-disabled’, !msg[key]);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {n”, ” if (msg[‘mode’] === ‘PAN’) {n”, ” fig.buttons[‘Pan’].classList.add(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” } else if (msg[‘mode’] === ‘ZOOM’) {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.add(‘active’);n”, ” } else {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Called whenever the canvas gets updated.n”, ” this.send_message(‘ack’, {});n”, “};n”, “n”, “// A function to construct a web socket function for onmessage handling.n”, “// Called in the figure constructor.n”, “mpl.figure.prototype._make_on_message_function = function (fig) {n”, ” return function socket_on_message(evt) {n”, ” if (evt.data instanceof Blob) {n”, ” / FIXME: We get "Resource interpreted as Image butn”, ” * transferred with MIME type text/plain:" errors onn”, ” * Chrome. But how to set the MIME type? It doesn’t seemn”, ” * to be part of the websocket stream /n”, ” evt.data.type = ‘image/png’;n”, “n”, ” / Free the memory for the previous frames /n”, ” if (fig.imageObj.src) {n”, ” (window.URL || window.webkitURL).revokeObjectURL(n”, ” fig.imageObj.srcn”, ” );n”, ” }n”, “n”, ” fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(n”, ” evt.datan”, ” );n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” } else if (n”, ” typeof evt.data === ‘string’ &&n”, ” evt.data.slice(0, 21) === ‘data:image/png;base64’n”, ” ) {n”, ” fig.imageObj.src = evt.data;n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” }n”, “n”, ” var msg = JSON.parse(evt.data);n”, ” var msg_type = msg[‘type’];n”, “n”, ” // Call the "handle_{type}" callback, which takesn”, ” // the figure and JSON message as its only arguments.n”, ” try {n”, ” var callback = fig[‘handle_’ + msg_type];n”, ” } catch (e) {n”, ” console.log(n”, ” "No handler for the ‘" + msg_type + "’ message type: ",n”, ” msgn”, ” );n”, ” return;n”, ” }n”, “n”, ” if (callback) {n”, ” try {n”, ” // console.log("Handling ‘" + msg_type + "’ message: ", msg);n”, ” callback(fig, msg);n”, ” } catch (e) {n”, ” console.log(n”, ” "Exception inside the ‘handler_" + msg_type + "’ callback:",n”, ” e,n”, ” e.stack,n”, ” msgn”, ” );n”, ” }n”, ” }n”, ” };n”, “};n”, “n”, “// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvasn”, “mpl.findpos = function (e) {n”, ” //this section is from http://www.quirksmode.org/js/events_properties.htmln”, ” var targ;n”, ” if (!e) {n”, ” e = window.event;n”, ” }n”, ” if (e.target) {n”, ” targ = e.target;n”, ” } else if (e.srcElement) {n”, ” targ = e.srcElement;n”, ” }n”, ” if (targ.nodeType === 3) {n”, ” // defeat Safari bugn”, ” targ = targ.parentNode;n”, ” }n”, “n”, ” // pageX,Y are the mouse positions relative to the documentn”, ” var boundingRect = targ.getBoundingClientRect();n”, ” var x = e.pageX - (boundingRect.left + document.body.scrollLeft);n”, ” var y = e.pageY - (boundingRect.top + document.body.scrollTop);n”, “n”, ” return { x: x, y: y };n”, “};n”, “n”, “/n”, ” * return a copy of an object with only non-object keysn”, ” * we need this to avoid circular referencesn”, ” * http://stackoverflow.com/a/24161582/3208463n”, ” /n”, “function simpleKeys(original) {n”, ” return Object.keys(original).reduce(function (obj, key) {n”, ” if (typeof original[key] !== ‘object’) {n”, ” obj[key] = original[key];n”, ” }n”, ” return obj;n”, ” }, {});n”, “}n”, “n”, “mpl.figure.prototype.mouse_event = function (event, name) {n”, ” var canvas_pos = mpl.findpos(event);n”, “n”, ” if (name === ‘button_press’) {n”, ” this.canvas.focus();n”, ” this.canvas_div.focus();n”, ” }n”, “n”, ” var x = canvas_pos.x * this.ratio;n”, ” var y = canvas_pos.y * this.ratio;n”, “n”, ” this.send_message(name, {n”, ” x: x,n”, ” y: y,n”, ” button: event.button,n”, ” step: event.step,n”, ” guiEvent: simpleKeys(event),n”, ” });n”, “n”, ” / This prevents the web browser from automatically changing ton”, ” * the text insertion cursor when the button is pressed. We wantn”, ” * to control all of the cursor setting manually through then”, ” * ‘cursor’ event from matplotlib */n”, ” event.preventDefault();n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (_event, _name) {n”, ” // Handle any extra behaviour associated with a key eventn”, “};n”, “n”, “mpl.figure.prototype.key_event = function (event, name) {n”, ” // Prevent repeat eventsn”, ” if (name === ‘key_press’) {n”, ” if (event.which === this._key) {n”, ” return;n”, ” } else {n”, ” this._key = event.which;n”, ” }n”, ” }n”, ” if (name === ‘key_release’) {n”, ” this._key = null;n”, ” }n”, “n”, ” var value = ‘’;n”, ” if (event.ctrlKey && event.which !== 17) {n”, ” value += ‘ctrl+’;n”, ” }n”, ” if (event.altKey && event.which !== 18) {n”, ” value += ‘alt+’;n”, ” }n”, ” if (event.shiftKey && event.which !== 16) {n”, ” value += ‘shift+’;n”, ” }n”, “n”, ” value += ‘k’;n”, ” value += event.which.toString();n”, “n”, ” this._key_event_extra(event, name);n”, “n”, ” this.send_message(name, { key: value, guiEvent: simpleKeys(event) });n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onclick = function (name) {n”, ” if (name === ‘download’) {n”, ” this.handle_save(this, null);n”, ” } else {n”, ” this.send_message(‘toolbar_button’, { name: name });n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {n”, ” this.message.textContent = tooltip;n”, “};n”,
- <<<<<<< HEAD
“n”, “///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////n”, “// prettier-ignoren”, “var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError("Constructor requires ‘new’ operator");i.set(this,e)}function h(){throw new TypeError("Function is not a constructor")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-linen”,
“n”, “mpl.extensions = ["eps", "jpeg", "pdf", "png", "ps", "raw", "svg", "tif"];n”, “n”, “mpl.default_extension = "png";/* global mpl */n”, “n”, “var comm_websocket_adapter = function (comm) {n”, ” // Create a "websocket"-like object which calls the given IPython commn”, ” // object with the appropriate methods. Currently this is a non binaryn”, ” // socket, so there is still some room for performance tuning.n”, ” var ws = {};n”, “n”, ” ws.close = function () {n”, ” comm.close();n”, ” };n”, ” ws.send = function (m) {n”, ” //console.log(‘sending’, m);n”, ” comm.send(m);n”, ” };n”, ” // Register the callback with on_msg.n”, ” comm.on_msg(function (msg) {n”, ” //console.log(‘receiving’, msg[‘content’][‘data’], msg);n”, ” // Pass the mpl event to the overridden (by mpl) onmessage function.n”, ” ws.onmessage(msg[‘content’][‘data’]);n”, ” });n”, ” return ws;n”, “};n”, “n”, “mpl.mpl_figure_comm = function (comm, msg) {n”, ” // This is the function which gets called when the mpl processn”, ” // starts-up an IPython Comm through the "matplotlib" channel.n”, “n”, ” var id = msg.content.data.id;n”, ” // Get hold of the div created by the display call when the Commn”, ” // socket was opened in Python.n”, ” var element = document.getElementById(id);n”, ” var ws_proxy = comm_websocket_adapter(comm);n”, “n”, ” function ondownload(figure, _format) {n”, ” window.open(figure.canvas.toDataURL());n”, ” }n”, “n”, ” var fig = new mpl.figure(id, ws_proxy, ondownload, element);n”, “n”, ” // Call onopen now - mpl needs it, as it is assuming we’ve passed it a realn”, ” // web socket which is closed, not our websocket->open comm proxy.n”, ” ws_proxy.onopen();n”, “n”, ” fig.parent_element = element;n”, ” fig.cell_info = mpl.find_output_cell("<div id=’" + id + "’></div>");n”, ” if (!fig.cell_info) {n”, ” console.error(‘Failed to find cell for figure’, id, fig);n”, ” return;n”, ” }n”,
- <<<<<<< HEAD
” fig.cell_info[0].output_area.element.on(n”,
” ‘cleared’,n”, ” { fig: fig },n”, ” fig._remove_fig_handlern”, ” );n”, “};n”, “n”, “mpl.figure.prototype.handle_close = function (fig, msg) {n”, ” var width = fig.canvas.width / fig.ratio;n”, ” fig.cell_info[0].output_area.element.off(n”, ” ‘cleared’,n”, ” fig._remove_fig_handlern”, ” );n”,
- <<<<<<< HEAD
” fig.resizeObserverInstance.unobserve(fig.canvas_div);n”,
” // Update the output cell to use the data from the current canvas.n”, ” fig.push_to_output();n”, ” var dataURL = fig.canvas.toDataURL();n”, ” // Re-enable the keyboard manager in IPython - without this line, in FF,n”, ” // the notebook keyboard shortcuts fail.n”, ” IPython.keyboard_manager.enable();n”, ” fig.parent_element.innerHTML =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, ” fig.close_ws(fig, msg);n”, “};n”, “n”, “mpl.figure.prototype.close_ws = function (fig, msg) {n”, ” fig.send_message(‘closing’, msg);n”, ” // fig.ws.close()n”, “};n”, “n”, “mpl.figure.prototype.push_to_output = function (_remove_interactive) {n”, ” // Turn the data on the canvas into data in the output cell.n”, ” var width = this.canvas.width / this.ratio;n”, ” var dataURL = this.canvas.toDataURL();n”, ” this.cell_info[1][‘text/html’] =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Tell IPython that the notebook contents must change.n”, ” IPython.notebook.set_dirty(true);n”, ” this.send_message(‘ack’, {});n”, ” var fig = this;n”, ” // Wait a second, then push the new image to the DOM son”, ” // that it is saved nicely (might be nice to debounce this).n”, ” setTimeout(function () {n”, ” fig.push_to_output();n”, ” }, 1000);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘btn-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” var button;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. */n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” continue;n”, ” }n”, “n”, ” button = fig.buttons[name] = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-default’;n”, ” button.href = ‘#’;n”, ” button.title = name;n”, ” button.innerHTML = ‘<i class="fa ‘ + image + ‘ fa-lg"></i>’;n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” // Add the status bar.n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message pull-right’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “n”, ” // Add the close button to the window.n”, ” var buttongrp = document.createElement(‘div’);n”, ” buttongrp.classList = ‘btn-group inline pull-right’;n”, ” button = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-mini btn-primary’;n”, ” button.href = ‘#’;n”, ” button.title = ‘Stop Interaction’;n”, ” button.innerHTML = ‘<i class="fa fa-power-off icon-remove icon-large"></i>’;n”, ” button.addEventListener(‘click’, function (_evt) {n”, ” fig.handle_close(fig, {});n”, ” });n”, ” button.addEventListener(n”, ” ‘mouseover’,n”, ” on_mouseover_closure(‘Stop Interaction’)n”, ” );n”, ” buttongrp.appendChild(button);n”, ” var titlebar = this.root.querySelector(‘.ui-dialog-titlebar’);n”, ” titlebar.insertBefore(buttongrp, titlebar.firstChild);n”, “};n”, “n”, “mpl.figure.prototype._remove_fig_handler = function (event) {n”, ” var fig = event.data.fig;n”,
- <<<<<<< HEAD
” if (event.target !== this) {n”, ” // Ignore bubbled events from children.n”, ” return;n”, ” }n”,
“};n”, “n”, “mpl.figure.prototype._root_extra_style = function (el) {n”, ” el.style.boxSizing = ‘content-box’; // override notebook setting of border-box.n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (el) {n”, ” // this is important to make the div ‘focusablen”, ” el.setAttribute(‘tabindex’, 0);n”, ” // reach out to IPython and tell the keyboard manager to turn it’s selfn”, ” // off when our div gets focusn”, “n”, ” // location in version 3n”, ” if (IPython.notebook.keyboard_manager) {n”, ” IPython.notebook.keyboard_manager.register_events(el);n”, ” } else {n”, ” // location in version 2n”, ” IPython.keyboard_manager.register_events(el);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (event, _name) {n”, ” var manager = IPython.notebook.keyboard_manager;n”, ” if (!manager) {n”, ” manager = IPython.keyboard_manager;n”, ” }n”, “n”, ” // Check for shift+entern”, ” if (event.shiftKey && event.which === 13) {n”, ” this.canvas_div.blur();n”, ” // select the cell after this onen”, ” var index = IPython.notebook.find_cell_index(this.cell_info[0]);n”, ” IPython.notebook.select(index + 1);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” fig.ondownload(fig, null);n”, “};n”, “n”, “mpl.find_output_cell = function (html_output) {n”, ” // Return the cell and output element which can be found uniquely in the notebook.n”, ” // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"n”, ” // IPython event is triggered only after the cells have been serialised, which forn”, ” // our purposes (turning an active figure into a static one), is too late.n”, ” var cells = IPython.notebook.get_cells();n”, ” var ncells = cells.length;n”, ” for (var i = 0; i < ncells; i++) {n”, ” var cell = cells[i];n”, ” if (cell.cell_type === ‘code’) {n”, ” for (var j = 0; j < cell.output_area.outputs.length; j++) {n”, ” var data = cell.output_area.outputs[j];n”, ” if (data.data) {n”, ” // IPython >= 3 moved mimebundle to data attribute of outputn”, ” data = data.data;n”, ” }n”, ” if (data[‘text/html’] === html_output) {n”, ” return [cell, data, j];n”, ” }n”, ” }n”, ” }n”, ” }n”, “};n”, “n”, “// Register the function which deals with the matplotlib target/channel.n”, “// The kernel may be null if the page has been refreshed.n”, “if (IPython.notebook.kernel !== null) {n”, ” IPython.notebook.kernel.comm_manager.register_target(n”, ” ‘matplotlib’,n”, ” mpl.mpl_figure_commn”, ” );n”, “}n”
], “text/plain”: [
“<IPython.core.display.Javascript object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/html”: [
], “text/plain”: [
“<IPython.core.display.HTML object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/plain”: [
- <<<<<<< HEAD
“[<matplotlib.lines.Line2D at 0x1a3bc32e850>]”
]
}, “execution_count”: 8,
}, “execution_count”: 17,
- >>>>>>> d27eb02fc99b5249297c72b2b388a2377fbe501e
“metadata”: {}, “output_type”: “execute_result”
}
], “source”: [
“n”, “center = np.array(center)n”, “out_tags={‘center’: center}n”, “#center[1] = 1057n”, “# center[0]= 1103n”, “# center[1]=1055n”, “n”, “polar_projection = warp(diff_pattern,center)n”, “below_zero = polar_projection<0.n”, “polar_projection[below_zero]=0.n”, “n”, “out_tags[‘polar_projection’] = polar_projectionn”, “n”, “# Sum over all angles (axis 1)n”, “profile = polar_projection.sum(axis=1)n”, “profile_0 = polar_projection[:,0:20].sum(axis=1)n”, “profile_360 = polar_projection[:,340:360].sum(axis=1)n”, “profile_180 = polar_projection[:,190:210].sum(axis=1)n”, “n”, “profile_90 = polar_projection[:,80:100].sum(axis=1)n”, “profile_270 = polar_projection[:,260:280].sum(axis=1)n”, “n”, “n”, “out_tags[‘radial_average’] = profilen”, “n”, “scale = ft.get_slope(main_dataset.dim_0.values)n”, “n”, “plt.figure()n”, “plt.imshow(np.log2(1+polar_projection),extent=(0,360,polar_projection.shape[0]*scale,scale),cmap="gray", vmin=np.max(np.log2(1+diff_pattern))*0.5)n”, “ax = plt.gca()n”, “ax.set_aspect("auto");n”, “plt.xlabel(‘angle [degree]’);n”, “plt.ylabel(‘distance [1/nm]’)n”, “n”, “plt.plot(profile/profile.max()*200,np.linspace(1,len(profile),len(profile))*scale,c=’r’);n”, “#plt.plot(profile_0/profile_0.max()*200,np.linspace(1,len(profile),len(profile))*scale,c=’orange’);n”, “#plt.plot(profile_360/profile_360.max()*200,np.linspace(1,len(profile),len(profile))*scale,c=’orange’);n”, “#plt.plot(profile_180/profile_180.max()*200,np.linspace(1,len(profile),len(profile))*scale,c=’b’);n”, “plt.plot(profile_90/profile_90.max()*200,np.linspace(1,len(profile),len(profile))*scale,c=’orange’);n”, “plt.plot(profile_270/profile_270.max()*200,np.linspace(1,len(profile),len(profile))*scale,c=’b’);n”, “n”, “n”, “plt.plot([0,360],[3.8,3.8])n”, “plt.plot([0,360],[6.3,6.3])”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Determine Bragg Peaksn”, “n”, “Peak finding is actually not as simple as it looks”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 9,
“metadata”: {}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
- <<<<<<< HEAD
“[ 0.43249485 0.66146272 0.91587145 1.81902247 3.44723839 4.03237849n”, ” 6.28389581 7.49233731 10.35443561]n”
- >>>>>>> d27eb02fc99b5249297c72b2b388a2377fbe501e
]
}, {
- “data”: {
- “application/javascript”: [
“/* Put everything inside the global mpl namespace /n”, “/ global mpl */n”, “window.mpl = {};n”, “n”, “mpl.get_websocket_type = function () {n”, ” if (typeof WebSocket !== ‘undefined’) {n”, ” return WebSocket;n”, ” } else if (typeof MozWebSocket !== ‘undefined’) {n”, ” return MozWebSocket;n”, ” } else {n”, ” alert(n”, ” ‘Your browser does not have WebSocket support. ‘ +n”, ” ‘Please try Chrome, Safari or Firefox ≥ 6. ‘ +n”, ” ‘Firefox 4 and 5 are also supported but you ‘ +n”, ” ‘have to enable WebSockets in about:config.’n”, ” );n”, ” }n”, “};n”, “n”, “mpl.figure = function (figure_id, websocket, ondownload, parent_element) {n”, ” this.id = figure_id;n”, “n”, ” this.ws = websocket;n”, “n”, ” this.supports_binary = this.ws.binaryType !== undefined;n”, “n”, ” if (!this.supports_binary) {n”, ” var warnings = document.getElementById(‘mpl-warnings’);n”, ” if (warnings) {n”, ” warnings.style.display = ‘block’;n”, ” warnings.textContent =n”, ” ‘This browser does not support binary websocket messages. ‘ +n”, ” ‘Performance may be slow.’;n”, ” }n”, ” }n”, “n”, ” this.imageObj = new Image();n”, “n”, ” this.context = undefined;n”, ” this.message = undefined;n”, ” this.canvas = undefined;n”, ” this.rubberband_canvas = undefined;n”, ” this.rubberband_context = undefined;n”, ” this.format_dropdown = undefined;n”, “n”, ” this.image_mode = ‘full’;n”, “n”, ” this.root = document.createElement(‘div’);n”, ” this.root.setAttribute(‘style’, ‘display: inline-block’);n”, ” this._root_extra_style(this.root);n”, “n”, ” parent_element.appendChild(this.root);n”, “n”, ” this._init_header(this);n”, ” this._init_canvas(this);n”, ” this._init_toolbar(this);n”, “n”, ” var fig = this;n”, “n”, ” this.waiting = false;n”, “n”, ” this.ws.onopen = function () {n”, ” fig.send_message(‘supports_binary’, { value: fig.supports_binary });n”, ” fig.send_message(‘send_image_mode’, {});n”, ” if (fig.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: fig.ratio });n”, ” }n”, ” fig.send_message(‘refresh’, {});n”, ” };n”, “n”, ” this.imageObj.onload = function () {n”, ” if (fig.image_mode === ‘full’) {n”, ” // Full images could contain transparency (where diff imagesn”, ” // almost always do), so we need to clear the canvas so thatn”, ” // there is no ghosting.n”, ” fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);n”, ” }n”, ” fig.context.drawImage(fig.imageObj, 0, 0);n”, ” };n”, “n”, ” this.imageObj.onunload = function () {n”, ” fig.ws.close();n”, ” };n”, “n”, ” this.ws.onmessage = this._make_on_message_function(this);n”, “n”, ” this.ondownload = ondownload;n”, “};n”, “n”, “mpl.figure.prototype._init_header = function () {n”, ” var titlebar = document.createElement(‘div’);n”, ” titlebar.classList =n”, ” ‘ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix’;n”, ” var titletext = document.createElement(‘div’);n”, ” titletext.classList = ‘ui-dialog-title’;n”, ” titletext.setAttribute(n”, ” ‘style’,n”, ” ‘width: 100%; text-align: center; padding: 3px;’n”, ” );n”, ” titlebar.appendChild(titletext);n”, ” this.root.appendChild(titlebar);n”, ” this.header = titletext;n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._root_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._init_canvas = function () {n”, ” var fig = this;n”, “n”, ” var canvas_div = (this.canvas_div = document.createElement(‘div’));n”, ” canvas_div.setAttribute(n”, ” ‘style’,n”, ” ‘border: 1px solid #ddd;’ +n”, ” ‘box-sizing: content-box;’ +n”, ” ‘clear: both;’ +n”, ” ‘min-height: 1px;’ +n”, ” ‘min-width: 1px;’ +n”, ” ‘outline: 0;’ +n”, ” ‘overflow: hidden;’ +n”, ” ‘position: relative;’ +n”, ” ‘resize: both;’n”, ” );n”, “n”, ” function on_keyboard_event_closure(name) {n”, ” return function (event) {n”, ” return fig.key_event(event, name);n”, ” };n”, ” }n”, “n”, ” canvas_div.addEventListener(n”, ” ‘keydown’,n”, ” on_keyboard_event_closure(‘key_press’)n”, ” );n”, ” canvas_div.addEventListener(n”, ” ‘keyup’,n”, ” on_keyboard_event_closure(‘key_release’)n”, ” );n”, “n”, ” this._canvas_extra_style(canvas_div);n”, ” this.root.appendChild(canvas_div);n”, “n”, ” var canvas = (this.canvas = document.createElement(‘canvas’));n”, ” canvas.classList.add(‘mpl-canvas’);n”, ” canvas.setAttribute(‘style’, ‘box-sizing: content-box;’);n”, “n”, ” this.context = canvas.getContext(‘2d’);n”, “n”, ” var backingStore =n”, ” this.context.backingStorePixelRatio ||n”, ” this.context.webkitBackingStorePixelRatio ||n”, ” this.context.mozBackingStorePixelRatio ||n”, ” this.context.msBackingStorePixelRatio ||n”, ” this.context.oBackingStorePixelRatio ||n”, ” this.context.backingStorePixelRatio ||n”, ” 1;n”, “n”, ” this.ratio = (window.devicePixelRatio || 1) / backingStore;n”, ” if (this.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: this.ratio });n”, ” }n”, “n”, ” var rubberband_canvas = (this.rubberband_canvas = document.createElement(n”, ” ‘canvas’n”, ” ));n”, ” rubberband_canvas.setAttribute(n”, ” ‘style’,n”, ” ‘box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;’n”, ” );n”, “n”,
- <<<<<<< HEAD
” // Apply a ponyfill if ResizeObserver is not implemented by browser.n”, ” if (this.ResizeObserver === undefined) {n”, ” if (window.ResizeObserver !== undefined) {n”, ” this.ResizeObserver = window.ResizeObserver;n”, ” } else {n”, ” var obs = _JSXTOOLS_RESIZE_OBSERVER({});n”, ” this.ResizeObserver = obs.ResizeObserver;n”, ” }n”, ” }n”, “n”, ” this.resizeObserverInstance = new this.ResizeObserver(function (entries) {n”,
” var nentries = entries.length;n”, ” for (var i = 0; i < nentries; i++) {n”, ” var entry = entries[i];n”, ” var width, height;n”, ” if (entry.contentBoxSize) {n”, ” if (entry.contentBoxSize instanceof Array) {n”, ” // Chrome 84 implements new version of spec.n”, ” width = entry.contentBoxSize[0].inlineSize;n”, ” height = entry.contentBoxSize[0].blockSize;n”, ” } else {n”, ” // Firefox implements old version of spec.n”, ” width = entry.contentBoxSize.inlineSize;n”, ” height = entry.contentBoxSize.blockSize;n”, ” }n”, ” } else {n”, ” // Chrome <84 implements even older version of spec.n”, ” width = entry.contentRect.width;n”, ” height = entry.contentRect.height;n”, ” }n”, “n”, ” // Keep the size of the canvas and rubber band canvas in sync withn”, ” // the canvas container.n”, ” if (entry.devicePixelContentBoxSize) {n”, ” // Chrome 84 implements new version of spec.n”, ” canvas.setAttribute(n”, ” ‘width’,n”, ” entry.devicePixelContentBoxSize[0].inlineSizen”, ” );n”, ” canvas.setAttribute(n”, ” ‘height’,n”, ” entry.devicePixelContentBoxSize[0].blockSizen”, ” );n”, ” } else {n”, ” canvas.setAttribute(‘width’, width * fig.ratio);n”, ” canvas.setAttribute(‘height’, height * fig.ratio);n”, ” }n”, ” canvas.setAttribute(n”, ” ‘style’,n”, ” ‘width: ‘ + width + ‘px; height: ‘ + height + ‘px;’n”, ” );n”, “n”, ” rubberband_canvas.setAttribute(‘width’, width);n”, ” rubberband_canvas.setAttribute(‘height’, height);n”, “n”, ” // And update the size in Python. We ignore the initial 0/0 sizen”, ” // that occurs as the element is placed into the DOM, which shouldn”, ” // otherwise not happen due to the minimum size styling.n”, ” if (width != 0 && height != 0) {n”, ” fig.request_resize(width, height);n”, ” }n”, ” }n”, ” });n”,
- <<<<<<< HEAD
” this.resizeObserverInstance.observe(canvas_div);n”,
“n”, ” function on_mouse_event_closure(name) {n”, ” return function (event) {n”, ” return fig.mouse_event(event, name);n”, ” };n”, ” }n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousedown’,n”, ” on_mouse_event_closure(‘button_press’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseup’,n”, ” on_mouse_event_closure(‘button_release’)n”, ” );n”, ” // Throttle sequential mouse events to 1 every 20ms.n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousemove’,n”, ” on_mouse_event_closure(‘motion_notify’)n”, ” );n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseenter’,n”, ” on_mouse_event_closure(‘figure_enter’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseleave’,n”, ” on_mouse_event_closure(‘figure_leave’)n”, ” );n”, “n”, ” canvas_div.addEventListener(‘wheel’, function (event) {n”, ” if (event.deltaY < 0) {n”, ” event.step = 1;n”, ” } else {n”, ” event.step = -1;n”, ” }n”, ” on_mouse_event_closure(‘scroll’)(event);n”, ” });n”, “n”, ” canvas_div.appendChild(canvas);n”, ” canvas_div.appendChild(rubberband_canvas);n”, “n”, ” this.rubberband_context = rubberband_canvas.getContext(‘2d’);n”, ” this.rubberband_context.strokeStyle = ‘#000000’;n”, “n”, ” this._resize_canvas = function (width, height, forward) {n”, ” if (forward) {n”, ” canvas_div.style.width = width + ‘px’;n”, ” canvas_div.style.height = height + ‘px’;n”, ” }n”, ” };n”, “n”, ” // Disable right mouse context menu.n”, ” this.rubberband_canvas.addEventListener(‘contextmenu’, function (_e) {n”, ” event.preventDefault();n”, ” return false;n”, ” });n”, “n”, ” function set_focus() {n”, ” canvas.focus();n”, ” canvas_div.focus();n”, ” }n”, “n”, ” window.setTimeout(set_focus, 100);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘mpl-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. /n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” continue;n”, ” }n”, “n”, ” var button = (fig.buttons[name] = document.createElement(‘button’));n”, ” button.classList = ‘mpl-widget’;n”, ” button.setAttribute(‘role’, ‘button’);n”, ” button.setAttribute(‘aria-disabled’, ‘false’);n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, “n”, ” var icon_img = document.createElement(‘img’);n”, ” icon_img.src = ‘_images/’ + image + ‘.png’;n”, ” icon_img.srcset = ‘_images/’ + image + ‘_large.png 2x’;n”, ” icon_img.alt = tooltip;n”, ” button.appendChild(icon_img);n”, “n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” var fmt_picker = document.createElement(‘select’);n”, ” fmt_picker.classList = ‘mpl-widget’;n”, ” toolbar.appendChild(fmt_picker);n”, ” this.format_dropdown = fmt_picker;n”, “n”, ” for (var ind in mpl.extensions) {n”, ” var fmt = mpl.extensions[ind];n”, ” var option = document.createElement(‘option’);n”, ” option.selected = fmt === mpl.default_extension;n”, ” option.innerHTML = fmt;n”, ” fmt_picker.appendChild(option);n”, ” }n”, “n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “};n”, “n”, “mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {n”, ” // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,n”, ” // which will in turn request a refresh of the image.n”, ” this.send_message(‘resize’, { width: x_pixels, height: y_pixels });n”, “};n”, “n”, “mpl.figure.prototype.send_message = function (type, properties) {n”, ” properties[‘type’] = type;n”, ” properties[‘figure_id’] = this.id;n”, ” this.ws.send(JSON.stringify(properties));n”, “};n”, “n”, “mpl.figure.prototype.send_draw_message = function () {n”, ” if (!this.waiting) {n”, ” this.waiting = true;n”, ” this.ws.send(JSON.stringify({ type: ‘draw’, figure_id: this.id }));n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” var format_dropdown = fig.format_dropdown;n”, ” var format = format_dropdown.options[format_dropdown.selectedIndex].value;n”, ” fig.ondownload(fig, format);n”, “};n”, “n”, “mpl.figure.prototype.handle_resize = function (fig, msg) {n”, ” var size = msg[‘size’];n”, ” if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {n”, ” fig._resize_canvas(size[0], size[1], msg[‘forward’]);n”, ” fig.send_message(‘refresh’, {});n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_rubberband = function (fig, msg) {n”, ” var x0 = msg[‘x0’] / fig.ratio;n”, ” var y0 = (fig.canvas.height - msg[‘y0’]) / fig.ratio;n”, ” var x1 = msg[‘x1’] / fig.ratio;n”, ” var y1 = (fig.canvas.height - msg[‘y1’]) / fig.ratio;n”, ” x0 = Math.floor(x0) + 0.5;n”, ” y0 = Math.floor(y0) + 0.5;n”, ” x1 = Math.floor(x1) + 0.5;n”, ” y1 = Math.floor(y1) + 0.5;n”, ” var min_x = Math.min(x0, x1);n”, ” var min_y = Math.min(y0, y1);n”, ” var width = Math.abs(x1 - x0);n”, ” var height = Math.abs(y1 - y0);n”, “n”, ” fig.rubberband_context.clearRect(n”, ” 0,n”, ” 0,n”, ” fig.canvas.width / fig.ratio,n”, ” fig.canvas.height / fig.ration”, ” );n”, “n”, ” fig.rubberband_context.strokeRect(min_x, min_y, width, height);n”, “};n”, “n”, “mpl.figure.prototype.handle_figure_label = function (fig, msg) {n”, ” // Updates the figure title.n”, ” fig.header.textContent = msg[‘label’];n”, “};n”, “n”, “mpl.figure.prototype.handle_cursor = function (fig, msg) {n”, ” var cursor = msg[‘cursor’];n”, ” switch (cursor) {n”, ” case 0:n”, ” cursor = ‘pointer’;n”, ” break;n”, ” case 1:n”, ” cursor = ‘default’;n”, ” break;n”, ” case 2:n”, ” cursor = ‘crosshair’;n”, ” break;n”, ” case 3:n”, ” cursor = ‘move’;n”, ” break;n”, ” }n”, ” fig.rubberband_canvas.style.cursor = cursor;n”, “};n”, “n”, “mpl.figure.prototype.handle_message = function (fig, msg) {n”, ” fig.message.textContent = msg[‘message’];n”, “};n”, “n”, “mpl.figure.prototype.handle_draw = function (fig, _msg) {n”, ” // Request the server to send over a new figure.n”, ” fig.send_draw_message();n”, “};n”, “n”, “mpl.figure.prototype.handle_image_mode = function (fig, msg) {n”, ” fig.image_mode = msg[‘mode’];n”, “};n”, “n”, “mpl.figure.prototype.handle_history_buttons = function (fig, msg) {n”, ” for (var key in msg) {n”, ” if (!(key in fig.buttons)) {n”, ” continue;n”, ” }n”, ” fig.buttons[key].disabled = !msg[key];n”, ” fig.buttons[key].setAttribute(‘aria-disabled’, !msg[key]);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {n”, ” if (msg[‘mode’] === ‘PAN’) {n”, ” fig.buttons[‘Pan’].classList.add(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” } else if (msg[‘mode’] === ‘ZOOM’) {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.add(‘active’);n”, ” } else {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Called whenever the canvas gets updated.n”, ” this.send_message(‘ack’, {});n”, “};n”, “n”, “// A function to construct a web socket function for onmessage handling.n”, “// Called in the figure constructor.n”, “mpl.figure.prototype._make_on_message_function = function (fig) {n”, ” return function socket_on_message(evt) {n”, ” if (evt.data instanceof Blob) {n”, ” / FIXME: We get "Resource interpreted as Image butn”, ” * transferred with MIME type text/plain:" errors onn”, ” * Chrome. But how to set the MIME type? It doesn’t seemn”, ” * to be part of the websocket stream /n”, ” evt.data.type = ‘image/png’;n”, “n”, ” / Free the memory for the previous frames /n”, ” if (fig.imageObj.src) {n”, ” (window.URL || window.webkitURL).revokeObjectURL(n”, ” fig.imageObj.srcn”, ” );n”, ” }n”, “n”, ” fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(n”, ” evt.datan”, ” );n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” } else if (n”, ” typeof evt.data === ‘string’ &&n”, ” evt.data.slice(0, 21) === ‘data:image/png;base64’n”, ” ) {n”, ” fig.imageObj.src = evt.data;n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” }n”, “n”, ” var msg = JSON.parse(evt.data);n”, ” var msg_type = msg[‘type’];n”, “n”, ” // Call the "handle_{type}" callback, which takesn”, ” // the figure and JSON message as its only arguments.n”, ” try {n”, ” var callback = fig[‘handle_’ + msg_type];n”, ” } catch (e) {n”, ” console.log(n”, ” "No handler for the ‘" + msg_type + "’ message type: ",n”, ” msgn”, ” );n”, ” return;n”, ” }n”, “n”, ” if (callback) {n”, ” try {n”, ” // console.log("Handling ‘" + msg_type + "’ message: ", msg);n”, ” callback(fig, msg);n”, ” } catch (e) {n”, ” console.log(n”, ” "Exception inside the ‘handler_" + msg_type + "’ callback:",n”, ” e,n”, ” e.stack,n”, ” msgn”, ” );n”, ” }n”, ” }n”, ” };n”, “};n”, “n”, “// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvasn”, “mpl.findpos = function (e) {n”, ” //this section is from http://www.quirksmode.org/js/events_properties.htmln”, ” var targ;n”, ” if (!e) {n”, ” e = window.event;n”, ” }n”, ” if (e.target) {n”, ” targ = e.target;n”, ” } else if (e.srcElement) {n”, ” targ = e.srcElement;n”, ” }n”, ” if (targ.nodeType === 3) {n”, ” // defeat Safari bugn”, ” targ = targ.parentNode;n”, ” }n”, “n”, ” // pageX,Y are the mouse positions relative to the documentn”, ” var boundingRect = targ.getBoundingClientRect();n”, ” var x = e.pageX - (boundingRect.left + document.body.scrollLeft);n”, ” var y = e.pageY - (boundingRect.top + document.body.scrollTop);n”, “n”, ” return { x: x, y: y };n”, “};n”, “n”, “/n”, ” * return a copy of an object with only non-object keysn”, ” * we need this to avoid circular referencesn”, ” * http://stackoverflow.com/a/24161582/3208463n”, ” /n”, “function simpleKeys(original) {n”, ” return Object.keys(original).reduce(function (obj, key) {n”, ” if (typeof original[key] !== ‘object’) {n”, ” obj[key] = original[key];n”, ” }n”, ” return obj;n”, ” }, {});n”, “}n”, “n”, “mpl.figure.prototype.mouse_event = function (event, name) {n”, ” var canvas_pos = mpl.findpos(event);n”, “n”, ” if (name === ‘button_press’) {n”, ” this.canvas.focus();n”, ” this.canvas_div.focus();n”, ” }n”, “n”, ” var x = canvas_pos.x * this.ratio;n”, ” var y = canvas_pos.y * this.ratio;n”, “n”, ” this.send_message(name, {n”, ” x: x,n”, ” y: y,n”, ” button: event.button,n”, ” step: event.step,n”, ” guiEvent: simpleKeys(event),n”, ” });n”, “n”, ” / This prevents the web browser from automatically changing ton”, ” * the text insertion cursor when the button is pressed. We wantn”, ” * to control all of the cursor setting manually through then”, ” * ‘cursor’ event from matplotlib */n”, ” event.preventDefault();n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (_event, _name) {n”, ” // Handle any extra behaviour associated with a key eventn”, “};n”, “n”, “mpl.figure.prototype.key_event = function (event, name) {n”, ” // Prevent repeat eventsn”, ” if (name === ‘key_press’) {n”, ” if (event.which === this._key) {n”, ” return;n”, ” } else {n”, ” this._key = event.which;n”, ” }n”, ” }n”, ” if (name === ‘key_release’) {n”, ” this._key = null;n”, ” }n”, “n”, ” var value = ‘’;n”, ” if (event.ctrlKey && event.which !== 17) {n”, ” value += ‘ctrl+’;n”, ” }n”, ” if (event.altKey && event.which !== 18) {n”, ” value += ‘alt+’;n”, ” }n”, ” if (event.shiftKey && event.which !== 16) {n”, ” value += ‘shift+’;n”, ” }n”, “n”, ” value += ‘k’;n”, ” value += event.which.toString();n”, “n”, ” this._key_event_extra(event, name);n”, “n”, ” this.send_message(name, { key: value, guiEvent: simpleKeys(event) });n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onclick = function (name) {n”, ” if (name === ‘download’) {n”, ” this.handle_save(this, null);n”, ” } else {n”, ” this.send_message(‘toolbar_button’, { name: name });n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {n”, ” this.message.textContent = tooltip;n”, “};n”,
- <<<<<<< HEAD
“n”, “///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////n”, “// prettier-ignoren”, “var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError("Constructor requires ‘new’ operator");i.set(this,e)}function h(){throw new TypeError("Function is not a constructor")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-linen”,
“n”, “mpl.extensions = ["eps", "jpeg", "pdf", "png", "ps", "raw", "svg", "tif"];n”, “n”, “mpl.default_extension = "png";/* global mpl */n”, “n”, “var comm_websocket_adapter = function (comm) {n”, ” // Create a "websocket"-like object which calls the given IPython commn”, ” // object with the appropriate methods. Currently this is a non binaryn”, ” // socket, so there is still some room for performance tuning.n”, ” var ws = {};n”, “n”, ” ws.close = function () {n”, ” comm.close();n”, ” };n”, ” ws.send = function (m) {n”, ” //console.log(‘sending’, m);n”, ” comm.send(m);n”, ” };n”, ” // Register the callback with on_msg.n”, ” comm.on_msg(function (msg) {n”, ” //console.log(‘receiving’, msg[‘content’][‘data’], msg);n”, ” // Pass the mpl event to the overridden (by mpl) onmessage function.n”, ” ws.onmessage(msg[‘content’][‘data’]);n”, ” });n”, ” return ws;n”, “};n”, “n”, “mpl.mpl_figure_comm = function (comm, msg) {n”, ” // This is the function which gets called when the mpl processn”, ” // starts-up an IPython Comm through the "matplotlib" channel.n”, “n”, ” var id = msg.content.data.id;n”, ” // Get hold of the div created by the display call when the Commn”, ” // socket was opened in Python.n”, ” var element = document.getElementById(id);n”, ” var ws_proxy = comm_websocket_adapter(comm);n”, “n”, ” function ondownload(figure, _format) {n”, ” window.open(figure.canvas.toDataURL());n”, ” }n”, “n”, ” var fig = new mpl.figure(id, ws_proxy, ondownload, element);n”, “n”, ” // Call onopen now - mpl needs it, as it is assuming we’ve passed it a realn”, ” // web socket which is closed, not our websocket->open comm proxy.n”, ” ws_proxy.onopen();n”, “n”, ” fig.parent_element = element;n”, ” fig.cell_info = mpl.find_output_cell("<div id=’" + id + "’></div>");n”, ” if (!fig.cell_info) {n”, ” console.error(‘Failed to find cell for figure’, id, fig);n”, ” return;n”, ” }n”,
- <<<<<<< HEAD
” fig.cell_info[0].output_area.element.on(n”,
” ‘cleared’,n”, ” { fig: fig },n”, ” fig._remove_fig_handlern”, ” );n”, “};n”, “n”, “mpl.figure.prototype.handle_close = function (fig, msg) {n”, ” var width = fig.canvas.width / fig.ratio;n”, ” fig.cell_info[0].output_area.element.off(n”, ” ‘cleared’,n”, ” fig._remove_fig_handlern”, ” );n”,
- <<<<<<< HEAD
” fig.resizeObserverInstance.unobserve(fig.canvas_div);n”,
” // Update the output cell to use the data from the current canvas.n”, ” fig.push_to_output();n”, ” var dataURL = fig.canvas.toDataURL();n”, ” // Re-enable the keyboard manager in IPython - without this line, in FF,n”, ” // the notebook keyboard shortcuts fail.n”, ” IPython.keyboard_manager.enable();n”, ” fig.parent_element.innerHTML =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, ” fig.close_ws(fig, msg);n”, “};n”, “n”, “mpl.figure.prototype.close_ws = function (fig, msg) {n”, ” fig.send_message(‘closing’, msg);n”, ” // fig.ws.close()n”, “};n”, “n”, “mpl.figure.prototype.push_to_output = function (_remove_interactive) {n”, ” // Turn the data on the canvas into data in the output cell.n”, ” var width = this.canvas.width / this.ratio;n”, ” var dataURL = this.canvas.toDataURL();n”, ” this.cell_info[1][‘text/html’] =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Tell IPython that the notebook contents must change.n”, ” IPython.notebook.set_dirty(true);n”, ” this.send_message(‘ack’, {});n”, ” var fig = this;n”, ” // Wait a second, then push the new image to the DOM son”, ” // that it is saved nicely (might be nice to debounce this).n”, ” setTimeout(function () {n”, ” fig.push_to_output();n”, ” }, 1000);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘btn-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” var button;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. */n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” continue;n”, ” }n”, “n”, ” button = fig.buttons[name] = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-default’;n”, ” button.href = ‘#’;n”, ” button.title = name;n”, ” button.innerHTML = ‘<i class="fa ‘ + image + ‘ fa-lg"></i>’;n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” // Add the status bar.n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message pull-right’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “n”, ” // Add the close button to the window.n”, ” var buttongrp = document.createElement(‘div’);n”, ” buttongrp.classList = ‘btn-group inline pull-right’;n”, ” button = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-mini btn-primary’;n”, ” button.href = ‘#’;n”, ” button.title = ‘Stop Interaction’;n”, ” button.innerHTML = ‘<i class="fa fa-power-off icon-remove icon-large"></i>’;n”, ” button.addEventListener(‘click’, function (_evt) {n”, ” fig.handle_close(fig, {});n”, ” });n”, ” button.addEventListener(n”, ” ‘mouseover’,n”, ” on_mouseover_closure(‘Stop Interaction’)n”, ” );n”, ” buttongrp.appendChild(button);n”, ” var titlebar = this.root.querySelector(‘.ui-dialog-titlebar’);n”, ” titlebar.insertBefore(buttongrp, titlebar.firstChild);n”, “};n”, “n”, “mpl.figure.prototype._remove_fig_handler = function (event) {n”, ” var fig = event.data.fig;n”,
- <<<<<<< HEAD
” if (event.target !== this) {n”, ” // Ignore bubbled events from children.n”, ” return;n”, ” }n”,
“};n”, “n”, “mpl.figure.prototype._root_extra_style = function (el) {n”, ” el.style.boxSizing = ‘content-box’; // override notebook setting of border-box.n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (el) {n”, ” // this is important to make the div ‘focusablen”, ” el.setAttribute(‘tabindex’, 0);n”, ” // reach out to IPython and tell the keyboard manager to turn it’s selfn”, ” // off when our div gets focusn”, “n”, ” // location in version 3n”, ” if (IPython.notebook.keyboard_manager) {n”, ” IPython.notebook.keyboard_manager.register_events(el);n”, ” } else {n”, ” // location in version 2n”, ” IPython.keyboard_manager.register_events(el);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (event, _name) {n”, ” var manager = IPython.notebook.keyboard_manager;n”, ” if (!manager) {n”, ” manager = IPython.keyboard_manager;n”, ” }n”, “n”, ” // Check for shift+entern”, ” if (event.shiftKey && event.which === 13) {n”, ” this.canvas_div.blur();n”, ” // select the cell after this onen”, ” var index = IPython.notebook.find_cell_index(this.cell_info[0]);n”, ” IPython.notebook.select(index + 1);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” fig.ondownload(fig, null);n”, “};n”, “n”, “mpl.find_output_cell = function (html_output) {n”, ” // Return the cell and output element which can be found uniquely in the notebook.n”, ” // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"n”, ” // IPython event is triggered only after the cells have been serialised, which forn”, ” // our purposes (turning an active figure into a static one), is too late.n”, ” var cells = IPython.notebook.get_cells();n”, ” var ncells = cells.length;n”, ” for (var i = 0; i < ncells; i++) {n”, ” var cell = cells[i];n”, ” if (cell.cell_type === ‘code’) {n”, ” for (var j = 0; j < cell.output_area.outputs.length; j++) {n”, ” var data = cell.output_area.outputs[j];n”, ” if (data.data) {n”, ” // IPython >= 3 moved mimebundle to data attribute of outputn”, ” data = data.data;n”, ” }n”, ” if (data[‘text/html’] === html_output) {n”, ” return [cell, data, j];n”, ” }n”, ” }n”, ” }n”, ” }n”, “};n”, “n”, “// Register the function which deals with the matplotlib target/channel.n”, “// The kernel may be null if the page has been refreshed.n”, “if (IPython.notebook.kernel !== null) {n”, ” IPython.notebook.kernel.comm_manager.register_target(n”, ” ‘matplotlib’,n”, ” mpl.mpl_figure_commn”, ” );n”, “}n”
], “text/plain”: [
“<IPython.core.display.Javascript object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/html”: [
], “text/plain”: [
“<IPython.core.display.HTML object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}
], “source”: [
“import scipy as spn”, “import scipy.signal as signaln”, “n”, “scale = ft.get_slope(main_dataset.dim_0.values)*4.28/3.75901247*1.005n”, “# find_Bragg peaks in profilen”, “peaks, g= signal.find_peaks(profile,rel_height =0.7, width=7) # np.std(second_deriv)*9)n”, “n”, “print(peaks*scale)n”, “n”, “out_tags[‘ring_radii_px’] = peaksn”, “n”, “n”, “plt.figure()n”, “n”, “plt.imshow(np.log2(1.+polar_projection),extent=(0,360,polar_projection.shape[0]*scale,scale),cmap="gray", vmin=np.max(np.log2(1+diff_pattern))*0.5)n”, “n”, “ax = plt.gca()n”, “ax.set_aspect("auto");n”, “plt.xlabel(‘angle [degree]’);n”, “plt.ylabel(‘distance [1/nm]’)n”, “n”, “plt.plot(profile/profile.max()*200,np.linspace(1,len(profile),len(profile))*scale,c=’r’);n”, “n”, “for i in peaks:n”, ” if i*scale > 3.5:n”, ” plt.plot((0,360),(i*scale,i*scale), linestyle=’–’, c = ‘steelblue’)”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Calculate Ring Patternn”, “n”, “see [Structure Factors notebook ](CH2_04-Structure_Factors.ipynb) for details.”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 10,
“metadata”: {}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
<<<<<<< HEAD¶
“[‘Au’]n”,
- >>>>>>> d27eb02fc99b5249297c72b2b388a2377fbe501e
” Of the evaluated 3375 Miller indices 855 are allowed. n”, ” Of the 854 allowed Bragg reflections there are 38 families of reflections.n”, “n”, ” index t hkl t 1/d [1/nm] d [pm] F multip. intensityn”, ” 0t {1 1 1} t 4.25 t 235 t 27.00, t 8 t 5832.86n”, ” 8t {0 0 2} t 4.90 t 204 t 24.48, t 6 t 3596.79n”, ” 14t {0 2 2} t 6.94 t 144 t 18.27, t 12 t 4004.58n”, ” 26t {3 1 1} t 8.13 t 123 t 15.54, t 24 t 5792.73n”, ” 50t {2 2 2} t 8.49 t 118 t 14.82, t 8 t 1756.96n”, ” 58t {0 0 4} t 9.81 t 102 t 12.57, t 6 t 948.09n”, ” 64t {3 3 1} t 10.69 t 94 t 11.33, t 24 t 3079.20n”, ” 88t {4 2 0} t 10.97 t 91 t 10.97, t 24 t 2889.10n”, “112t {2 2 4} t 12.01 t 83 t 9.77, t 24 t 2291.50n”, “136t {5 1 1} t 12.74 t 78 t 9.05, t 24 t 1965.11n”, “160t {3 3 3} t 12.74 t 78 t 9.05, t 8 t 655.04n”, “168t {0 4 4} t 13.87 t 72 t 8.08, t 12 t 783.51n”, “180t {1 5 3} t 14.51 t 69 t 7.60, t 48 t 2775.70n”, “228t {4 4 2} t 14.71 t 68 t 7.46, t 30 t 1669.40n”, “258t {6 2 0} t 15.51 t 64 t 6.94, t 24 t 1155.47n”, “282t {5 3 3} t 16.08 t 62 t 6.60, t 24 t 1045.13n”, “306t {6 2 2} t 16.27 t 61 t 6.49, t 24 t 1012.15n”, “330t {4 4 4} t 16.99 t 59 t 6.11, t 8 t 298.61n”, “338t {7 1 1} t 17.51 t 57 t 5.85, t 24 t 822.23n”, “362t {5 5 1} t 17.51 t 57 t 5.85, t 24 t 822.23n”, “386t {6 0 4} t 17.68 t 57 t 5.77, t 24 t 799.86n”, “410t {2 6 4} t 18.35 t 54 t 5.48, t 48 t 1439.07n”, “458t {1 3 7} t 18.83 t 53 t 5.27, t 48 t 1334.98n”, “506t {5 5 3} t 18.83 t 53 t 5.27, t 24 t 667.49n”, “530t {3 7 3} t 20.07 t 50 t 4.81, t 24 t 554.73n”, “554t {6 4 4} t 20.22 t 49 t 4.76, t 24 t 542.78n”, “578t {0 6 6} t 20.81 t 48 t 4.56, t 12 t 249.42n”, “590t {7 1 5} t 21.24 t 47 t 4.42, t 32 t 625.92n”, “622t {5 5 5} t 21.24 t 47 t 4.42, t 24 t 469.44n”, “646t {6 2 6} t 21.38 t 47 t 4.38, t 24 t 460.25n”, “670t {5 3 7} t 22.34 t 45 t 4.10, t 48 t 806.10n”, “718t {4 6 6} t 23.00 t 43 t 3.92, t 24 t 368.66n”, “742t {7 5 5} t 24.40 t 41 t 3.58, t 48 t 614.38n”, “790t {7 7 3} t 25.36 t 39 t 3.37, t 24 t 271.77n”, “814t {6 6 6} t 25.48 t 39 t 3.34, t 8 t 89.26n”, “822t {7 7 5} t 27.19 t 37 t 3.01, t 8 t 72.39n”, “830t {5 7 7} t 27.19 t 37 t 3.01, t 16 t 144.77n”
]
}
], “source”: [
“#Initialize the dictionary with all the inputn”, “tags = ks.structure_by_name(‘gold’)n”, “ft.h5_add_crystal_structure(main_dataset.h5_dataset.file, tags)n”, “n”, “n”, “#Reciprocal Lattice n”, “# We use the linear algebra package of numpy to invert the unit_cell "matrix"n”, “reciprocal_unit_cell = np.linalg.inv(tags[‘unit_cell’]).T # transposed of inverted unit_celln”, “n”, “#INPUTn”, “hkl_max = 7# maximum allowed Miller indexn”, “n”, “acceleration_voltage = 200.0 *1000.0 #Vn”, “wave_length = ks.get_wavelength(acceleration_voltage)n”, “n”, “n”, “n”, “h = np.linspace(-hkl_max,hkl_max,2*hkl_max+1) # all to be evaluated single Miller Indexn”, “hkl = np.array(list(itertools.product(h,h,h) )) # all to be evaluated Miller indicesn”, “g_hkl = np.dot(hkl,reciprocal_unit_cell) n”, “n”, “# Calculate Structure Factorsn”, “n”, “structure_factors = []n”, “n”, “base = np.dot(tags[‘base’],tags[‘unit_cell’]) # transformation from relative to Carthesian coordinatesn”, “for j in range(len(g_hkl)):n”, ” F = 0n”, ” for b in range(len(base)):n”, ” f = ks.feq(tags[‘elements’][b],np.linalg.norm(g_hkl[j])) # Atomic form factor for element and momentum change (g vector)n”, ” F += f * np.exp(-2*np.pi*1j*(g_hkl[j]*base[b]).sum()) n”, ” structure_factors.append(F)n”, “F = structure_factors = np.array(structure_factors)n”, “n”, “# Allowed reflections have a non zero structure factor F (with a bit of numerical error)n”, “allowed = np.absolute(structure_factors) > 0.001n”, “n”, “distances = np.linalg.norm(g_hkl, axis = 1)n”, “n”, “print(f’ Of the evaluated {hkl.shape[0]} Miller indices {allowed.sum()} are allowed. ‘)n”, “# We select now all the n”, “zero = distances == 0.n”, “allowed = np.logical_and(allowed,np.logical_not(zero))n”, “n”, “F = F[allowed]n”, “g_hkl = g_hkl[allowed]n”, “hkl = hkl[allowed]n”, “distances = distances[allowed]n”, “n”, “sorted_allowed = np.argsort(distances)n”, “n”, “distances = distances[sorted_allowed]n”, “hkl = hkl[sorted_allowed]n”, “F = F[sorted_allowed]n”, “n”, “# How many have unique distances and what is their muliplicityn”, “n”, “unique, indices = np.unique(distances, return_index=True)n”, “n”, “print(f’ Of the {allowed.sum()} allowed Bragg reflections there are {len(unique)} families of reflections.’)n”, “n”, “intensity = np.absolute(F[indices]**2*(np.roll(indices,-1)-indices))n”, “print(‘\n index \t hkl \t 1/d [1/nm] d [pm] F multip. intensity’ )n”, “family = []n”, “#out_tags[‘reflections’] = {}n”, “reflection = 0n”, “for j in range(len(unique)-1):n”, ” i = indices[j] n”, ” i2 = indices[j+1] n”, ” family.append(hkl[i+np.argmax(hkl[i:i2].sum(axis=1))])n”, ” index = ‘{‘+f’{family[j][0]:.0f} {family[j][1]:.0f} {family[j][2]:.0f}’+’}’n”, ” print(f’{i:3g}\t {index} \t {distances[i]:.2f} \t {1/distances[i]*1000:.0f} \t {np.absolute(F[i]):.2f}, \t {indices[j+1]-indices[j]:3g} \t {intensity[j]:.2f}’) n”, ” #out_tags[‘reflections’+str(reflection)]={}n”, ” out_tags[‘reflections-‘+str(reflection)+’-index’] = indexn”, ” out_tags[‘reflections-‘+str(reflection)+’-recip_distances’] = distances[i]n”, ” out_tags[‘reflections-‘+str(reflection)+’-structure_factor’] = np.absolute(F[i])n”, ” out_tags[‘reflections-‘+str(reflection)+’-multiplicity’] = indices[j+1]-indices[j]n”, ” out_tags[‘reflections-‘+str(reflection)+’-intensity’] = intensity[j]n”, ” reflection +=1n”, ” n”, ” n”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“We can have a look what we saved in the file”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 11,
“metadata”: {}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“/n”, “├ Measurement_000n”, ” —————n”, ” ├ Channel_000n”, ” ———–n”, ” ├ GOLD_NP_DIFFn”, ” ————n”, ” ├ GOLD_NP_DIFFn”, ” ├ __dict__n”, ” ——–n”, ” ├ _axesn”, ” —–n”, ” ├ _original_metadatan”, ” ——————n”, ” ├ original_metadatan”, ” —————–n”, ” ├ un”, ” ├ vn”, “├ Structure_000n”, ” ————-n”, ” ├ _goldn”, ” ├ elementsn”, ” ├ relative_positionsn”, ” ├ titlen”, ” ├ unit_celln”,
<<<<<<< HEAD¶
” ├ zone_axisn”, “├ Structure_001n”, ” ————-n”, ” ├ _goldn”, ” ├ elementsn”, ” ├ relative_positionsn”, ” ├ titlen”, ” ├ unit_celln”,
- >>>>>>> d27eb02fc99b5249297c72b2b388a2377fbe501e
” ├ zone_axisn”
]
}
], “source”: [
“ft.h5_tree(main_dataset)n”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Comparison n”, “Comparison between experimental profile and kinematic theoryn”, “n”, “The grain size will have an influence on the width of the diffraction rings”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 12,
“metadata”: {}, “outputs”: [
- {
- “data”: {
- “application/javascript”: [
“/* Put everything inside the global mpl namespace /n”, “/ global mpl */n”, “window.mpl = {};n”, “n”, “mpl.get_websocket_type = function () {n”, ” if (typeof WebSocket !== ‘undefined’) {n”, ” return WebSocket;n”, ” } else if (typeof MozWebSocket !== ‘undefined’) {n”, ” return MozWebSocket;n”, ” } else {n”, ” alert(n”, ” ‘Your browser does not have WebSocket support. ‘ +n”, ” ‘Please try Chrome, Safari or Firefox ≥ 6. ‘ +n”, ” ‘Firefox 4 and 5 are also supported but you ‘ +n”, ” ‘have to enable WebSockets in about:config.’n”, ” );n”, ” }n”, “};n”, “n”, “mpl.figure = function (figure_id, websocket, ondownload, parent_element) {n”, ” this.id = figure_id;n”, “n”, ” this.ws = websocket;n”, “n”, ” this.supports_binary = this.ws.binaryType !== undefined;n”, “n”, ” if (!this.supports_binary) {n”, ” var warnings = document.getElementById(‘mpl-warnings’);n”, ” if (warnings) {n”, ” warnings.style.display = ‘block’;n”, ” warnings.textContent =n”, ” ‘This browser does not support binary websocket messages. ‘ +n”, ” ‘Performance may be slow.’;n”, ” }n”, ” }n”, “n”, ” this.imageObj = new Image();n”, “n”, ” this.context = undefined;n”, ” this.message = undefined;n”, ” this.canvas = undefined;n”, ” this.rubberband_canvas = undefined;n”, ” this.rubberband_context = undefined;n”, ” this.format_dropdown = undefined;n”, “n”, ” this.image_mode = ‘full’;n”, “n”, ” this.root = document.createElement(‘div’);n”, ” this.root.setAttribute(‘style’, ‘display: inline-block’);n”, ” this._root_extra_style(this.root);n”, “n”, ” parent_element.appendChild(this.root);n”, “n”, ” this._init_header(this);n”, ” this._init_canvas(this);n”, ” this._init_toolbar(this);n”, “n”, ” var fig = this;n”, “n”, ” this.waiting = false;n”, “n”, ” this.ws.onopen = function () {n”, ” fig.send_message(‘supports_binary’, { value: fig.supports_binary });n”, ” fig.send_message(‘send_image_mode’, {});n”, ” if (fig.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: fig.ratio });n”, ” }n”, ” fig.send_message(‘refresh’, {});n”, ” };n”, “n”, ” this.imageObj.onload = function () {n”, ” if (fig.image_mode === ‘full’) {n”, ” // Full images could contain transparency (where diff imagesn”, ” // almost always do), so we need to clear the canvas so thatn”, ” // there is no ghosting.n”, ” fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);n”, ” }n”, ” fig.context.drawImage(fig.imageObj, 0, 0);n”, ” };n”, “n”, ” this.imageObj.onunload = function () {n”, ” fig.ws.close();n”, ” };n”, “n”, ” this.ws.onmessage = this._make_on_message_function(this);n”, “n”, ” this.ondownload = ondownload;n”, “};n”, “n”, “mpl.figure.prototype._init_header = function () {n”, ” var titlebar = document.createElement(‘div’);n”, ” titlebar.classList =n”, ” ‘ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix’;n”, ” var titletext = document.createElement(‘div’);n”, ” titletext.classList = ‘ui-dialog-title’;n”, ” titletext.setAttribute(n”, ” ‘style’,n”, ” ‘width: 100%; text-align: center; padding: 3px;’n”, ” );n”, ” titlebar.appendChild(titletext);n”, ” this.root.appendChild(titlebar);n”, ” this.header = titletext;n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._root_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._init_canvas = function () {n”, ” var fig = this;n”, “n”, ” var canvas_div = (this.canvas_div = document.createElement(‘div’));n”, ” canvas_div.setAttribute(n”, ” ‘style’,n”, ” ‘border: 1px solid #ddd;’ +n”, ” ‘box-sizing: content-box;’ +n”, ” ‘clear: both;’ +n”, ” ‘min-height: 1px;’ +n”, ” ‘min-width: 1px;’ +n”, ” ‘outline: 0;’ +n”, ” ‘overflow: hidden;’ +n”, ” ‘position: relative;’ +n”, ” ‘resize: both;’n”, ” );n”, “n”, ” function on_keyboard_event_closure(name) {n”, ” return function (event) {n”, ” return fig.key_event(event, name);n”, ” };n”, ” }n”, “n”, ” canvas_div.addEventListener(n”, ” ‘keydown’,n”, ” on_keyboard_event_closure(‘key_press’)n”, ” );n”, ” canvas_div.addEventListener(n”, ” ‘keyup’,n”, ” on_keyboard_event_closure(‘key_release’)n”, ” );n”, “n”, ” this._canvas_extra_style(canvas_div);n”, ” this.root.appendChild(canvas_div);n”, “n”, ” var canvas = (this.canvas = document.createElement(‘canvas’));n”, ” canvas.classList.add(‘mpl-canvas’);n”, ” canvas.setAttribute(‘style’, ‘box-sizing: content-box;’);n”, “n”, ” this.context = canvas.getContext(‘2d’);n”, “n”, ” var backingStore =n”, ” this.context.backingStorePixelRatio ||n”, ” this.context.webkitBackingStorePixelRatio ||n”, ” this.context.mozBackingStorePixelRatio ||n”, ” this.context.msBackingStorePixelRatio ||n”, ” this.context.oBackingStorePixelRatio ||n”, ” this.context.backingStorePixelRatio ||n”, ” 1;n”, “n”, ” this.ratio = (window.devicePixelRatio || 1) / backingStore;n”, ” if (this.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: this.ratio });n”, ” }n”, “n”, ” var rubberband_canvas = (this.rubberband_canvas = document.createElement(n”, ” ‘canvas’n”, ” ));n”, ” rubberband_canvas.setAttribute(n”, ” ‘style’,n”, ” ‘box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;’n”, ” );n”, “n”,
- <<<<<<< HEAD
” // Apply a ponyfill if ResizeObserver is not implemented by browser.n”, ” if (this.ResizeObserver === undefined) {n”, ” if (window.ResizeObserver !== undefined) {n”, ” this.ResizeObserver = window.ResizeObserver;n”, ” } else {n”, ” var obs = _JSXTOOLS_RESIZE_OBSERVER({});n”, ” this.ResizeObserver = obs.ResizeObserver;n”, ” }n”, ” }n”, “n”, ” this.resizeObserverInstance = new this.ResizeObserver(function (entries) {n”,
” var nentries = entries.length;n”, ” for (var i = 0; i < nentries; i++) {n”, ” var entry = entries[i];n”, ” var width, height;n”, ” if (entry.contentBoxSize) {n”, ” if (entry.contentBoxSize instanceof Array) {n”, ” // Chrome 84 implements new version of spec.n”, ” width = entry.contentBoxSize[0].inlineSize;n”, ” height = entry.contentBoxSize[0].blockSize;n”, ” } else {n”, ” // Firefox implements old version of spec.n”, ” width = entry.contentBoxSize.inlineSize;n”, ” height = entry.contentBoxSize.blockSize;n”, ” }n”, ” } else {n”, ” // Chrome <84 implements even older version of spec.n”, ” width = entry.contentRect.width;n”, ” height = entry.contentRect.height;n”, ” }n”, “n”, ” // Keep the size of the canvas and rubber band canvas in sync withn”, ” // the canvas container.n”, ” if (entry.devicePixelContentBoxSize) {n”, ” // Chrome 84 implements new version of spec.n”, ” canvas.setAttribute(n”, ” ‘width’,n”, ” entry.devicePixelContentBoxSize[0].inlineSizen”, ” );n”, ” canvas.setAttribute(n”, ” ‘height’,n”, ” entry.devicePixelContentBoxSize[0].blockSizen”, ” );n”, ” } else {n”, ” canvas.setAttribute(‘width’, width * fig.ratio);n”, ” canvas.setAttribute(‘height’, height * fig.ratio);n”, ” }n”, ” canvas.setAttribute(n”, ” ‘style’,n”, ” ‘width: ‘ + width + ‘px; height: ‘ + height + ‘px;’n”, ” );n”, “n”, ” rubberband_canvas.setAttribute(‘width’, width);n”, ” rubberband_canvas.setAttribute(‘height’, height);n”, “n”, ” // And update the size in Python. We ignore the initial 0/0 sizen”, ” // that occurs as the element is placed into the DOM, which shouldn”, ” // otherwise not happen due to the minimum size styling.n”, ” if (width != 0 && height != 0) {n”, ” fig.request_resize(width, height);n”, ” }n”, ” }n”, ” });n”,
- <<<<<<< HEAD
” this.resizeObserverInstance.observe(canvas_div);n”,
“n”, ” function on_mouse_event_closure(name) {n”, ” return function (event) {n”, ” return fig.mouse_event(event, name);n”, ” };n”, ” }n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousedown’,n”, ” on_mouse_event_closure(‘button_press’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseup’,n”, ” on_mouse_event_closure(‘button_release’)n”, ” );n”, ” // Throttle sequential mouse events to 1 every 20ms.n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousemove’,n”, ” on_mouse_event_closure(‘motion_notify’)n”, ” );n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseenter’,n”, ” on_mouse_event_closure(‘figure_enter’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseleave’,n”, ” on_mouse_event_closure(‘figure_leave’)n”, ” );n”, “n”, ” canvas_div.addEventListener(‘wheel’, function (event) {n”, ” if (event.deltaY < 0) {n”, ” event.step = 1;n”, ” } else {n”, ” event.step = -1;n”, ” }n”, ” on_mouse_event_closure(‘scroll’)(event);n”, ” });n”, “n”, ” canvas_div.appendChild(canvas);n”, ” canvas_div.appendChild(rubberband_canvas);n”, “n”, ” this.rubberband_context = rubberband_canvas.getContext(‘2d’);n”, ” this.rubberband_context.strokeStyle = ‘#000000’;n”, “n”, ” this._resize_canvas = function (width, height, forward) {n”, ” if (forward) {n”, ” canvas_div.style.width = width + ‘px’;n”, ” canvas_div.style.height = height + ‘px’;n”, ” }n”, ” };n”, “n”, ” // Disable right mouse context menu.n”, ” this.rubberband_canvas.addEventListener(‘contextmenu’, function (_e) {n”, ” event.preventDefault();n”, ” return false;n”, ” });n”, “n”, ” function set_focus() {n”, ” canvas.focus();n”, ” canvas_div.focus();n”, ” }n”, “n”, ” window.setTimeout(set_focus, 100);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘mpl-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. /n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” continue;n”, ” }n”, “n”, ” var button = (fig.buttons[name] = document.createElement(‘button’));n”, ” button.classList = ‘mpl-widget’;n”, ” button.setAttribute(‘role’, ‘button’);n”, ” button.setAttribute(‘aria-disabled’, ‘false’);n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, “n”, ” var icon_img = document.createElement(‘img’);n”, ” icon_img.src = ‘_images/’ + image + ‘.png’;n”, ” icon_img.srcset = ‘_images/’ + image + ‘_large.png 2x’;n”, ” icon_img.alt = tooltip;n”, ” button.appendChild(icon_img);n”, “n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” var fmt_picker = document.createElement(‘select’);n”, ” fmt_picker.classList = ‘mpl-widget’;n”, ” toolbar.appendChild(fmt_picker);n”, ” this.format_dropdown = fmt_picker;n”, “n”, ” for (var ind in mpl.extensions) {n”, ” var fmt = mpl.extensions[ind];n”, ” var option = document.createElement(‘option’);n”, ” option.selected = fmt === mpl.default_extension;n”, ” option.innerHTML = fmt;n”, ” fmt_picker.appendChild(option);n”, ” }n”, “n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “};n”, “n”, “mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {n”, ” // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,n”, ” // which will in turn request a refresh of the image.n”, ” this.send_message(‘resize’, { width: x_pixels, height: y_pixels });n”, “};n”, “n”, “mpl.figure.prototype.send_message = function (type, properties) {n”, ” properties[‘type’] = type;n”, ” properties[‘figure_id’] = this.id;n”, ” this.ws.send(JSON.stringify(properties));n”, “};n”, “n”, “mpl.figure.prototype.send_draw_message = function () {n”, ” if (!this.waiting) {n”, ” this.waiting = true;n”, ” this.ws.send(JSON.stringify({ type: ‘draw’, figure_id: this.id }));n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” var format_dropdown = fig.format_dropdown;n”, ” var format = format_dropdown.options[format_dropdown.selectedIndex].value;n”, ” fig.ondownload(fig, format);n”, “};n”, “n”, “mpl.figure.prototype.handle_resize = function (fig, msg) {n”, ” var size = msg[‘size’];n”, ” if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {n”, ” fig._resize_canvas(size[0], size[1], msg[‘forward’]);n”, ” fig.send_message(‘refresh’, {});n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_rubberband = function (fig, msg) {n”, ” var x0 = msg[‘x0’] / fig.ratio;n”, ” var y0 = (fig.canvas.height - msg[‘y0’]) / fig.ratio;n”, ” var x1 = msg[‘x1’] / fig.ratio;n”, ” var y1 = (fig.canvas.height - msg[‘y1’]) / fig.ratio;n”, ” x0 = Math.floor(x0) + 0.5;n”, ” y0 = Math.floor(y0) + 0.5;n”, ” x1 = Math.floor(x1) + 0.5;n”, ” y1 = Math.floor(y1) + 0.5;n”, ” var min_x = Math.min(x0, x1);n”, ” var min_y = Math.min(y0, y1);n”, ” var width = Math.abs(x1 - x0);n”, ” var height = Math.abs(y1 - y0);n”, “n”, ” fig.rubberband_context.clearRect(n”, ” 0,n”, ” 0,n”, ” fig.canvas.width / fig.ratio,n”, ” fig.canvas.height / fig.ration”, ” );n”, “n”, ” fig.rubberband_context.strokeRect(min_x, min_y, width, height);n”, “};n”, “n”, “mpl.figure.prototype.handle_figure_label = function (fig, msg) {n”, ” // Updates the figure title.n”, ” fig.header.textContent = msg[‘label’];n”, “};n”, “n”, “mpl.figure.prototype.handle_cursor = function (fig, msg) {n”, ” var cursor = msg[‘cursor’];n”, ” switch (cursor) {n”, ” case 0:n”, ” cursor = ‘pointer’;n”, ” break;n”, ” case 1:n”, ” cursor = ‘default’;n”, ” break;n”, ” case 2:n”, ” cursor = ‘crosshair’;n”, ” break;n”, ” case 3:n”, ” cursor = ‘move’;n”, ” break;n”, ” }n”, ” fig.rubberband_canvas.style.cursor = cursor;n”, “};n”, “n”, “mpl.figure.prototype.handle_message = function (fig, msg) {n”, ” fig.message.textContent = msg[‘message’];n”, “};n”, “n”, “mpl.figure.prototype.handle_draw = function (fig, _msg) {n”, ” // Request the server to send over a new figure.n”, ” fig.send_draw_message();n”, “};n”, “n”, “mpl.figure.prototype.handle_image_mode = function (fig, msg) {n”, ” fig.image_mode = msg[‘mode’];n”, “};n”, “n”, “mpl.figure.prototype.handle_history_buttons = function (fig, msg) {n”, ” for (var key in msg) {n”, ” if (!(key in fig.buttons)) {n”, ” continue;n”, ” }n”, ” fig.buttons[key].disabled = !msg[key];n”, ” fig.buttons[key].setAttribute(‘aria-disabled’, !msg[key]);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {n”, ” if (msg[‘mode’] === ‘PAN’) {n”, ” fig.buttons[‘Pan’].classList.add(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” } else if (msg[‘mode’] === ‘ZOOM’) {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.add(‘active’);n”, ” } else {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Called whenever the canvas gets updated.n”, ” this.send_message(‘ack’, {});n”, “};n”, “n”, “// A function to construct a web socket function for onmessage handling.n”, “// Called in the figure constructor.n”, “mpl.figure.prototype._make_on_message_function = function (fig) {n”, ” return function socket_on_message(evt) {n”, ” if (evt.data instanceof Blob) {n”, ” / FIXME: We get "Resource interpreted as Image butn”, ” * transferred with MIME type text/plain:" errors onn”, ” * Chrome. But how to set the MIME type? It doesn’t seemn”, ” * to be part of the websocket stream /n”, ” evt.data.type = ‘image/png’;n”, “n”, ” / Free the memory for the previous frames /n”, ” if (fig.imageObj.src) {n”, ” (window.URL || window.webkitURL).revokeObjectURL(n”, ” fig.imageObj.srcn”, ” );n”, ” }n”, “n”, ” fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(n”, ” evt.datan”, ” );n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” } else if (n”, ” typeof evt.data === ‘string’ &&n”, ” evt.data.slice(0, 21) === ‘data:image/png;base64’n”, ” ) {n”, ” fig.imageObj.src = evt.data;n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” }n”, “n”, ” var msg = JSON.parse(evt.data);n”, ” var msg_type = msg[‘type’];n”, “n”, ” // Call the "handle_{type}" callback, which takesn”, ” // the figure and JSON message as its only arguments.n”, ” try {n”, ” var callback = fig[‘handle_’ + msg_type];n”, ” } catch (e) {n”, ” console.log(n”, ” "No handler for the ‘" + msg_type + "’ message type: ",n”, ” msgn”, ” );n”, ” return;n”, ” }n”, “n”, ” if (callback) {n”, ” try {n”, ” // console.log("Handling ‘" + msg_type + "’ message: ", msg);n”, ” callback(fig, msg);n”, ” } catch (e) {n”, ” console.log(n”, ” "Exception inside the ‘handler_" + msg_type + "’ callback:",n”, ” e,n”, ” e.stack,n”, ” msgn”, ” );n”, ” }n”, ” }n”, ” };n”, “};n”, “n”, “// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvasn”, “mpl.findpos = function (e) {n”, ” //this section is from http://www.quirksmode.org/js/events_properties.htmln”, ” var targ;n”, ” if (!e) {n”, ” e = window.event;n”, ” }n”, ” if (e.target) {n”, ” targ = e.target;n”, ” } else if (e.srcElement) {n”, ” targ = e.srcElement;n”, ” }n”, ” if (targ.nodeType === 3) {n”, ” // defeat Safari bugn”, ” targ = targ.parentNode;n”, ” }n”, “n”, ” // pageX,Y are the mouse positions relative to the documentn”, ” var boundingRect = targ.getBoundingClientRect();n”, ” var x = e.pageX - (boundingRect.left + document.body.scrollLeft);n”, ” var y = e.pageY - (boundingRect.top + document.body.scrollTop);n”, “n”, ” return { x: x, y: y };n”, “};n”, “n”, “/n”, ” * return a copy of an object with only non-object keysn”, ” * we need this to avoid circular referencesn”, ” * http://stackoverflow.com/a/24161582/3208463n”, ” /n”, “function simpleKeys(original) {n”, ” return Object.keys(original).reduce(function (obj, key) {n”, ” if (typeof original[key] !== ‘object’) {n”, ” obj[key] = original[key];n”, ” }n”, ” return obj;n”, ” }, {});n”, “}n”, “n”, “mpl.figure.prototype.mouse_event = function (event, name) {n”, ” var canvas_pos = mpl.findpos(event);n”, “n”, ” if (name === ‘button_press’) {n”, ” this.canvas.focus();n”, ” this.canvas_div.focus();n”, ” }n”, “n”, ” var x = canvas_pos.x * this.ratio;n”, ” var y = canvas_pos.y * this.ratio;n”, “n”, ” this.send_message(name, {n”, ” x: x,n”, ” y: y,n”, ” button: event.button,n”, ” step: event.step,n”, ” guiEvent: simpleKeys(event),n”, ” });n”, “n”, ” / This prevents the web browser from automatically changing ton”, ” * the text insertion cursor when the button is pressed. We wantn”, ” * to control all of the cursor setting manually through then”, ” * ‘cursor’ event from matplotlib */n”, ” event.preventDefault();n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (_event, _name) {n”, ” // Handle any extra behaviour associated with a key eventn”, “};n”, “n”, “mpl.figure.prototype.key_event = function (event, name) {n”, ” // Prevent repeat eventsn”, ” if (name === ‘key_press’) {n”, ” if (event.which === this._key) {n”, ” return;n”, ” } else {n”, ” this._key = event.which;n”, ” }n”, ” }n”, ” if (name === ‘key_release’) {n”, ” this._key = null;n”, ” }n”, “n”, ” var value = ‘’;n”, ” if (event.ctrlKey && event.which !== 17) {n”, ” value += ‘ctrl+’;n”, ” }n”, ” if (event.altKey && event.which !== 18) {n”, ” value += ‘alt+’;n”, ” }n”, ” if (event.shiftKey && event.which !== 16) {n”, ” value += ‘shift+’;n”, ” }n”, “n”, ” value += ‘k’;n”, ” value += event.which.toString();n”, “n”, ” this._key_event_extra(event, name);n”, “n”, ” this.send_message(name, { key: value, guiEvent: simpleKeys(event) });n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onclick = function (name) {n”, ” if (name === ‘download’) {n”, ” this.handle_save(this, null);n”, ” } else {n”, ” this.send_message(‘toolbar_button’, { name: name });n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {n”, ” this.message.textContent = tooltip;n”, “};n”,
- <<<<<<< HEAD
“n”, “///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////n”, “// prettier-ignoren”, “var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError("Constructor requires ‘new’ operator");i.set(this,e)}function h(){throw new TypeError("Function is not a constructor")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-linen”,
“n”, “mpl.extensions = ["eps", "jpeg", "pdf", "png", "ps", "raw", "svg", "tif"];n”, “n”, “mpl.default_extension = "png";/* global mpl */n”, “n”, “var comm_websocket_adapter = function (comm) {n”, ” // Create a "websocket"-like object which calls the given IPython commn”, ” // object with the appropriate methods. Currently this is a non binaryn”, ” // socket, so there is still some room for performance tuning.n”, ” var ws = {};n”, “n”, ” ws.close = function () {n”, ” comm.close();n”, ” };n”, ” ws.send = function (m) {n”, ” //console.log(‘sending’, m);n”, ” comm.send(m);n”, ” };n”, ” // Register the callback with on_msg.n”, ” comm.on_msg(function (msg) {n”, ” //console.log(‘receiving’, msg[‘content’][‘data’], msg);n”, ” // Pass the mpl event to the overridden (by mpl) onmessage function.n”, ” ws.onmessage(msg[‘content’][‘data’]);n”, ” });n”, ” return ws;n”, “};n”, “n”, “mpl.mpl_figure_comm = function (comm, msg) {n”, ” // This is the function which gets called when the mpl processn”, ” // starts-up an IPython Comm through the "matplotlib" channel.n”, “n”, ” var id = msg.content.data.id;n”, ” // Get hold of the div created by the display call when the Commn”, ” // socket was opened in Python.n”, ” var element = document.getElementById(id);n”, ” var ws_proxy = comm_websocket_adapter(comm);n”, “n”, ” function ondownload(figure, _format) {n”, ” window.open(figure.canvas.toDataURL());n”, ” }n”, “n”, ” var fig = new mpl.figure(id, ws_proxy, ondownload, element);n”, “n”, ” // Call onopen now - mpl needs it, as it is assuming we’ve passed it a realn”, ” // web socket which is closed, not our websocket->open comm proxy.n”, ” ws_proxy.onopen();n”, “n”, ” fig.parent_element = element;n”, ” fig.cell_info = mpl.find_output_cell("<div id=’" + id + "’></div>");n”, ” if (!fig.cell_info) {n”, ” console.error(‘Failed to find cell for figure’, id, fig);n”, ” return;n”, ” }n”,
- <<<<<<< HEAD
” fig.cell_info[0].output_area.element.on(n”,
” ‘cleared’,n”, ” { fig: fig },n”, ” fig._remove_fig_handlern”, ” );n”, “};n”, “n”, “mpl.figure.prototype.handle_close = function (fig, msg) {n”, ” var width = fig.canvas.width / fig.ratio;n”, ” fig.cell_info[0].output_area.element.off(n”, ” ‘cleared’,n”, ” fig._remove_fig_handlern”, ” );n”,
- <<<<<<< HEAD
” fig.resizeObserverInstance.unobserve(fig.canvas_div);n”,
” // Update the output cell to use the data from the current canvas.n”, ” fig.push_to_output();n”, ” var dataURL = fig.canvas.toDataURL();n”, ” // Re-enable the keyboard manager in IPython - without this line, in FF,n”, ” // the notebook keyboard shortcuts fail.n”, ” IPython.keyboard_manager.enable();n”, ” fig.parent_element.innerHTML =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, ” fig.close_ws(fig, msg);n”, “};n”, “n”, “mpl.figure.prototype.close_ws = function (fig, msg) {n”, ” fig.send_message(‘closing’, msg);n”, ” // fig.ws.close()n”, “};n”, “n”, “mpl.figure.prototype.push_to_output = function (_remove_interactive) {n”, ” // Turn the data on the canvas into data in the output cell.n”, ” var width = this.canvas.width / this.ratio;n”, ” var dataURL = this.canvas.toDataURL();n”, ” this.cell_info[1][‘text/html’] =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Tell IPython that the notebook contents must change.n”, ” IPython.notebook.set_dirty(true);n”, ” this.send_message(‘ack’, {});n”, ” var fig = this;n”, ” // Wait a second, then push the new image to the DOM son”, ” // that it is saved nicely (might be nice to debounce this).n”, ” setTimeout(function () {n”, ” fig.push_to_output();n”, ” }, 1000);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘btn-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” var button;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. */n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” continue;n”, ” }n”, “n”, ” button = fig.buttons[name] = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-default’;n”, ” button.href = ‘#’;n”, ” button.title = name;n”, ” button.innerHTML = ‘<i class="fa ‘ + image + ‘ fa-lg"></i>’;n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” // Add the status bar.n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message pull-right’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “n”, ” // Add the close button to the window.n”, ” var buttongrp = document.createElement(‘div’);n”, ” buttongrp.classList = ‘btn-group inline pull-right’;n”, ” button = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-mini btn-primary’;n”, ” button.href = ‘#’;n”, ” button.title = ‘Stop Interaction’;n”, ” button.innerHTML = ‘<i class="fa fa-power-off icon-remove icon-large"></i>’;n”, ” button.addEventListener(‘click’, function (_evt) {n”, ” fig.handle_close(fig, {});n”, ” });n”, ” button.addEventListener(n”, ” ‘mouseover’,n”, ” on_mouseover_closure(‘Stop Interaction’)n”, ” );n”, ” buttongrp.appendChild(button);n”, ” var titlebar = this.root.querySelector(‘.ui-dialog-titlebar’);n”, ” titlebar.insertBefore(buttongrp, titlebar.firstChild);n”, “};n”, “n”, “mpl.figure.prototype._remove_fig_handler = function (event) {n”, ” var fig = event.data.fig;n”,
- <<<<<<< HEAD
” if (event.target !== this) {n”, ” // Ignore bubbled events from children.n”, ” return;n”, ” }n”,
“};n”, “n”, “mpl.figure.prototype._root_extra_style = function (el) {n”, ” el.style.boxSizing = ‘content-box’; // override notebook setting of border-box.n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (el) {n”, ” // this is important to make the div ‘focusablen”, ” el.setAttribute(‘tabindex’, 0);n”, ” // reach out to IPython and tell the keyboard manager to turn it’s selfn”, ” // off when our div gets focusn”, “n”, ” // location in version 3n”, ” if (IPython.notebook.keyboard_manager) {n”, ” IPython.notebook.keyboard_manager.register_events(el);n”, ” } else {n”, ” // location in version 2n”, ” IPython.keyboard_manager.register_events(el);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (event, _name) {n”, ” var manager = IPython.notebook.keyboard_manager;n”, ” if (!manager) {n”, ” manager = IPython.keyboard_manager;n”, ” }n”, “n”, ” // Check for shift+entern”, ” if (event.shiftKey && event.which === 13) {n”, ” this.canvas_div.blur();n”, ” // select the cell after this onen”, ” var index = IPython.notebook.find_cell_index(this.cell_info[0]);n”, ” IPython.notebook.select(index + 1);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” fig.ondownload(fig, null);n”, “};n”, “n”, “mpl.find_output_cell = function (html_output) {n”, ” // Return the cell and output element which can be found uniquely in the notebook.n”, ” // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"n”, ” // IPython event is triggered only after the cells have been serialised, which forn”, ” // our purposes (turning an active figure into a static one), is too late.n”, ” var cells = IPython.notebook.get_cells();n”, ” var ncells = cells.length;n”, ” for (var i = 0; i < ncells; i++) {n”, ” var cell = cells[i];n”, ” if (cell.cell_type === ‘code’) {n”, ” for (var j = 0; j < cell.output_area.outputs.length; j++) {n”, ” var data = cell.output_area.outputs[j];n”, ” if (data.data) {n”, ” // IPython >= 3 moved mimebundle to data attribute of outputn”, ” data = data.data;n”, ” }n”, ” if (data[‘text/html’] === html_output) {n”, ” return [cell, data, j];n”, ” }n”, ” }n”, ” }n”, ” }n”, “};n”, “n”, “// Register the function which deals with the matplotlib target/channel.n”, “// The kernel may be null if the page has been refreshed.n”, “if (IPython.notebook.kernel !== null) {n”, ” IPython.notebook.kernel.comm_manager.register_target(n”, ” ‘matplotlib’,n”, ” mpl.mpl_figure_commn”, ” );n”, “}n”
], “text/plain”: [
“<IPython.core.display.Javascript object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/html”: [
], “text/plain”: [
“<IPython.core.display.HTML object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}
], “source”: [
“# ——-Input of grain size —-n”, “resolution = 0 # 1/nmn”, “thickness = 10 # nmn”, “# ——————————-n”, “n”, “from scipy import signaln”, “n”, “width = (1/thickness + resolution) / scalen”, “scale = ft.get_slope(main_dataset.dim_0.values) # 1.085*1.0n”, “n”, “intensity2 = intensity/intensity.max()*10n”, “n”, “gauss = signal.gaussian(len(profile), std=width)n”, “simulated_profile = np.zeros(len(profile))n”, “rec_dist = np.linspace(1,len(profile),len(profile))*scalen”, “n”, “x =[]n”, “yAu = []n”, “yC = []n”, “for i in rec_dist:n”, ” yAu.append(ks.feq(‘Au’, i))n”, ” yC.append(ks.feq(‘C’, i))n”, ” n”, “plt.figure()n”, “plt.plot(rec_dist,profile/profile.max()*150, color=’blue’, label=’experiment’);n”, “for j in range(len(unique)-1):n”, ” if unique[j] < len(profile)*scale:n”, ” # plot linesn”, ” plt.plot([unique[j],unique[j]], [0, intensity2[j]],c=’r’)n”, ” # plot indicesn”, ” index = ‘{‘+f’{family[j][0]:.0f} {family[j][1]:.0f} {family[j][2]:.0f}’+’}’ # pretty index stringn”, ” plt.text(unique[j],-3, index, horizontalalignment=’center’,n”, ” verticalalignment=’top’, rotation = ‘vertical’, fontsize=8, color = ‘red’)n”, ” n”, ” # place Gaussian with appropriate width in profilen”, ” g = np.roll(gauss,int(-len(profile)/2+unique[j]/scale)) intensity2[j]*np.array(yAu)*1.3#rec_dist**2*10n”, ” simulated_profile = simulated_profile + gn”, “plt.plot(np.linspace(1,len(profile),len(profile))*scale,simulated_profile, label=’simulated’);n”, “plt.plot(rec_dist,np.array(yAu)**2, label=’form_factor’)n”, “n”, “plt.ylim(-35,210);”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Publication Quality Outputn”, “n”, “Now we have all the ingredients to make a publication quality plot of the data.”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 13,
“metadata”: {}, “outputs”: [
- {
- “data”: {
- “application/javascript”: [
“/* Put everything inside the global mpl namespace /n”, “/ global mpl */n”, “window.mpl = {};n”, “n”, “mpl.get_websocket_type = function () {n”, ” if (typeof WebSocket !== ‘undefined’) {n”, ” return WebSocket;n”, ” } else if (typeof MozWebSocket !== ‘undefined’) {n”, ” return MozWebSocket;n”, ” } else {n”, ” alert(n”, ” ‘Your browser does not have WebSocket support. ‘ +n”, ” ‘Please try Chrome, Safari or Firefox ≥ 6. ‘ +n”, ” ‘Firefox 4 and 5 are also supported but you ‘ +n”, ” ‘have to enable WebSockets in about:config.’n”, ” );n”, ” }n”, “};n”, “n”, “mpl.figure = function (figure_id, websocket, ondownload, parent_element) {n”, ” this.id = figure_id;n”, “n”, ” this.ws = websocket;n”, “n”, ” this.supports_binary = this.ws.binaryType !== undefined;n”, “n”, ” if (!this.supports_binary) {n”, ” var warnings = document.getElementById(‘mpl-warnings’);n”, ” if (warnings) {n”, ” warnings.style.display = ‘block’;n”, ” warnings.textContent =n”, ” ‘This browser does not support binary websocket messages. ‘ +n”, ” ‘Performance may be slow.’;n”, ” }n”, ” }n”, “n”, ” this.imageObj = new Image();n”, “n”, ” this.context = undefined;n”, ” this.message = undefined;n”, ” this.canvas = undefined;n”, ” this.rubberband_canvas = undefined;n”, ” this.rubberband_context = undefined;n”, ” this.format_dropdown = undefined;n”, “n”, ” this.image_mode = ‘full’;n”, “n”, ” this.root = document.createElement(‘div’);n”, ” this.root.setAttribute(‘style’, ‘display: inline-block’);n”, ” this._root_extra_style(this.root);n”, “n”, ” parent_element.appendChild(this.root);n”, “n”, ” this._init_header(this);n”, ” this._init_canvas(this);n”, ” this._init_toolbar(this);n”, “n”, ” var fig = this;n”, “n”, ” this.waiting = false;n”, “n”, ” this.ws.onopen = function () {n”, ” fig.send_message(‘supports_binary’, { value: fig.supports_binary });n”, ” fig.send_message(‘send_image_mode’, {});n”, ” if (fig.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: fig.ratio });n”, ” }n”, ” fig.send_message(‘refresh’, {});n”, ” };n”, “n”, ” this.imageObj.onload = function () {n”, ” if (fig.image_mode === ‘full’) {n”, ” // Full images could contain transparency (where diff imagesn”, ” // almost always do), so we need to clear the canvas so thatn”, ” // there is no ghosting.n”, ” fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);n”, ” }n”, ” fig.context.drawImage(fig.imageObj, 0, 0);n”, ” };n”, “n”, ” this.imageObj.onunload = function () {n”, ” fig.ws.close();n”, ” };n”, “n”, ” this.ws.onmessage = this._make_on_message_function(this);n”, “n”, ” this.ondownload = ondownload;n”, “};n”, “n”, “mpl.figure.prototype._init_header = function () {n”, ” var titlebar = document.createElement(‘div’);n”, ” titlebar.classList =n”, ” ‘ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix’;n”, ” var titletext = document.createElement(‘div’);n”, ” titletext.classList = ‘ui-dialog-title’;n”, ” titletext.setAttribute(n”, ” ‘style’,n”, ” ‘width: 100%; text-align: center; padding: 3px;’n”, ” );n”, ” titlebar.appendChild(titletext);n”, ” this.root.appendChild(titlebar);n”, ” this.header = titletext;n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._root_extra_style = function (_canvas_div) {};n”, “n”, “mpl.figure.prototype._init_canvas = function () {n”, ” var fig = this;n”, “n”, ” var canvas_div = (this.canvas_div = document.createElement(‘div’));n”, ” canvas_div.setAttribute(n”, ” ‘style’,n”, ” ‘border: 1px solid #ddd;’ +n”, ” ‘box-sizing: content-box;’ +n”, ” ‘clear: both;’ +n”, ” ‘min-height: 1px;’ +n”, ” ‘min-width: 1px;’ +n”, ” ‘outline: 0;’ +n”, ” ‘overflow: hidden;’ +n”, ” ‘position: relative;’ +n”, ” ‘resize: both;’n”, ” );n”, “n”, ” function on_keyboard_event_closure(name) {n”, ” return function (event) {n”, ” return fig.key_event(event, name);n”, ” };n”, ” }n”, “n”, ” canvas_div.addEventListener(n”, ” ‘keydown’,n”, ” on_keyboard_event_closure(‘key_press’)n”, ” );n”, ” canvas_div.addEventListener(n”, ” ‘keyup’,n”, ” on_keyboard_event_closure(‘key_release’)n”, ” );n”, “n”, ” this._canvas_extra_style(canvas_div);n”, ” this.root.appendChild(canvas_div);n”, “n”, ” var canvas = (this.canvas = document.createElement(‘canvas’));n”, ” canvas.classList.add(‘mpl-canvas’);n”, ” canvas.setAttribute(‘style’, ‘box-sizing: content-box;’);n”, “n”, ” this.context = canvas.getContext(‘2d’);n”, “n”, ” var backingStore =n”, ” this.context.backingStorePixelRatio ||n”, ” this.context.webkitBackingStorePixelRatio ||n”, ” this.context.mozBackingStorePixelRatio ||n”, ” this.context.msBackingStorePixelRatio ||n”, ” this.context.oBackingStorePixelRatio ||n”, ” this.context.backingStorePixelRatio ||n”, ” 1;n”, “n”, ” this.ratio = (window.devicePixelRatio || 1) / backingStore;n”, ” if (this.ratio !== 1) {n”, ” fig.send_message(‘set_dpi_ratio’, { dpi_ratio: this.ratio });n”, ” }n”, “n”, ” var rubberband_canvas = (this.rubberband_canvas = document.createElement(n”, ” ‘canvas’n”, ” ));n”, ” rubberband_canvas.setAttribute(n”, ” ‘style’,n”, ” ‘box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;’n”, ” );n”, “n”,
- <<<<<<< HEAD
” // Apply a ponyfill if ResizeObserver is not implemented by browser.n”, ” if (this.ResizeObserver === undefined) {n”, ” if (window.ResizeObserver !== undefined) {n”, ” this.ResizeObserver = window.ResizeObserver;n”, ” } else {n”, ” var obs = _JSXTOOLS_RESIZE_OBSERVER({});n”, ” this.ResizeObserver = obs.ResizeObserver;n”, ” }n”, ” }n”, “n”, ” this.resizeObserverInstance = new this.ResizeObserver(function (entries) {n”,
” var nentries = entries.length;n”, ” for (var i = 0; i < nentries; i++) {n”, ” var entry = entries[i];n”, ” var width, height;n”, ” if (entry.contentBoxSize) {n”, ” if (entry.contentBoxSize instanceof Array) {n”, ” // Chrome 84 implements new version of spec.n”, ” width = entry.contentBoxSize[0].inlineSize;n”, ” height = entry.contentBoxSize[0].blockSize;n”, ” } else {n”, ” // Firefox implements old version of spec.n”, ” width = entry.contentBoxSize.inlineSize;n”, ” height = entry.contentBoxSize.blockSize;n”, ” }n”, ” } else {n”, ” // Chrome <84 implements even older version of spec.n”, ” width = entry.contentRect.width;n”, ” height = entry.contentRect.height;n”, ” }n”, “n”, ” // Keep the size of the canvas and rubber band canvas in sync withn”, ” // the canvas container.n”, ” if (entry.devicePixelContentBoxSize) {n”, ” // Chrome 84 implements new version of spec.n”, ” canvas.setAttribute(n”, ” ‘width’,n”, ” entry.devicePixelContentBoxSize[0].inlineSizen”, ” );n”, ” canvas.setAttribute(n”, ” ‘height’,n”, ” entry.devicePixelContentBoxSize[0].blockSizen”, ” );n”, ” } else {n”, ” canvas.setAttribute(‘width’, width * fig.ratio);n”, ” canvas.setAttribute(‘height’, height * fig.ratio);n”, ” }n”, ” canvas.setAttribute(n”, ” ‘style’,n”, ” ‘width: ‘ + width + ‘px; height: ‘ + height + ‘px;’n”, ” );n”, “n”, ” rubberband_canvas.setAttribute(‘width’, width);n”, ” rubberband_canvas.setAttribute(‘height’, height);n”, “n”, ” // And update the size in Python. We ignore the initial 0/0 sizen”, ” // that occurs as the element is placed into the DOM, which shouldn”, ” // otherwise not happen due to the minimum size styling.n”, ” if (width != 0 && height != 0) {n”, ” fig.request_resize(width, height);n”, ” }n”, ” }n”, ” });n”,
- <<<<<<< HEAD
” this.resizeObserverInstance.observe(canvas_div);n”,
“n”, ” function on_mouse_event_closure(name) {n”, ” return function (event) {n”, ” return fig.mouse_event(event, name);n”, ” };n”, ” }n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousedown’,n”, ” on_mouse_event_closure(‘button_press’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseup’,n”, ” on_mouse_event_closure(‘button_release’)n”, ” );n”, ” // Throttle sequential mouse events to 1 every 20ms.n”, ” rubberband_canvas.addEventListener(n”, ” ‘mousemove’,n”, ” on_mouse_event_closure(‘motion_notify’)n”, ” );n”, “n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseenter’,n”, ” on_mouse_event_closure(‘figure_enter’)n”, ” );n”, ” rubberband_canvas.addEventListener(n”, ” ‘mouseleave’,n”, ” on_mouse_event_closure(‘figure_leave’)n”, ” );n”, “n”, ” canvas_div.addEventListener(‘wheel’, function (event) {n”, ” if (event.deltaY < 0) {n”, ” event.step = 1;n”, ” } else {n”, ” event.step = -1;n”, ” }n”, ” on_mouse_event_closure(‘scroll’)(event);n”, ” });n”, “n”, ” canvas_div.appendChild(canvas);n”, ” canvas_div.appendChild(rubberband_canvas);n”, “n”, ” this.rubberband_context = rubberband_canvas.getContext(‘2d’);n”, ” this.rubberband_context.strokeStyle = ‘#000000’;n”, “n”, ” this._resize_canvas = function (width, height, forward) {n”, ” if (forward) {n”, ” canvas_div.style.width = width + ‘px’;n”, ” canvas_div.style.height = height + ‘px’;n”, ” }n”, ” };n”, “n”, ” // Disable right mouse context menu.n”, ” this.rubberband_canvas.addEventListener(‘contextmenu’, function (_e) {n”, ” event.preventDefault();n”, ” return false;n”, ” });n”, “n”, ” function set_focus() {n”, ” canvas.focus();n”, ” canvas_div.focus();n”, ” }n”, “n”, ” window.setTimeout(set_focus, 100);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘mpl-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. /n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘mpl-button-group’;n”, ” continue;n”, ” }n”, “n”, ” var button = (fig.buttons[name] = document.createElement(‘button’));n”, ” button.classList = ‘mpl-widget’;n”, ” button.setAttribute(‘role’, ‘button’);n”, ” button.setAttribute(‘aria-disabled’, ‘false’);n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, “n”, ” var icon_img = document.createElement(‘img’);n”, ” icon_img.src = ‘_images/’ + image + ‘.png’;n”, ” icon_img.srcset = ‘_images/’ + image + ‘_large.png 2x’;n”, ” icon_img.alt = tooltip;n”, ” button.appendChild(icon_img);n”, “n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” var fmt_picker = document.createElement(‘select’);n”, ” fmt_picker.classList = ‘mpl-widget’;n”, ” toolbar.appendChild(fmt_picker);n”, ” this.format_dropdown = fmt_picker;n”, “n”, ” for (var ind in mpl.extensions) {n”, ” var fmt = mpl.extensions[ind];n”, ” var option = document.createElement(‘option’);n”, ” option.selected = fmt === mpl.default_extension;n”, ” option.innerHTML = fmt;n”, ” fmt_picker.appendChild(option);n”, ” }n”, “n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “};n”, “n”, “mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {n”, ” // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,n”, ” // which will in turn request a refresh of the image.n”, ” this.send_message(‘resize’, { width: x_pixels, height: y_pixels });n”, “};n”, “n”, “mpl.figure.prototype.send_message = function (type, properties) {n”, ” properties[‘type’] = type;n”, ” properties[‘figure_id’] = this.id;n”, ” this.ws.send(JSON.stringify(properties));n”, “};n”, “n”, “mpl.figure.prototype.send_draw_message = function () {n”, ” if (!this.waiting) {n”, ” this.waiting = true;n”, ” this.ws.send(JSON.stringify({ type: ‘draw’, figure_id: this.id }));n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” var format_dropdown = fig.format_dropdown;n”, ” var format = format_dropdown.options[format_dropdown.selectedIndex].value;n”, ” fig.ondownload(fig, format);n”, “};n”, “n”, “mpl.figure.prototype.handle_resize = function (fig, msg) {n”, ” var size = msg[‘size’];n”, ” if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {n”, ” fig._resize_canvas(size[0], size[1], msg[‘forward’]);n”, ” fig.send_message(‘refresh’, {});n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_rubberband = function (fig, msg) {n”, ” var x0 = msg[‘x0’] / fig.ratio;n”, ” var y0 = (fig.canvas.height - msg[‘y0’]) / fig.ratio;n”, ” var x1 = msg[‘x1’] / fig.ratio;n”, ” var y1 = (fig.canvas.height - msg[‘y1’]) / fig.ratio;n”, ” x0 = Math.floor(x0) + 0.5;n”, ” y0 = Math.floor(y0) + 0.5;n”, ” x1 = Math.floor(x1) + 0.5;n”, ” y1 = Math.floor(y1) + 0.5;n”, ” var min_x = Math.min(x0, x1);n”, ” var min_y = Math.min(y0, y1);n”, ” var width = Math.abs(x1 - x0);n”, ” var height = Math.abs(y1 - y0);n”, “n”, ” fig.rubberband_context.clearRect(n”, ” 0,n”, ” 0,n”, ” fig.canvas.width / fig.ratio,n”, ” fig.canvas.height / fig.ration”, ” );n”, “n”, ” fig.rubberband_context.strokeRect(min_x, min_y, width, height);n”, “};n”, “n”, “mpl.figure.prototype.handle_figure_label = function (fig, msg) {n”, ” // Updates the figure title.n”, ” fig.header.textContent = msg[‘label’];n”, “};n”, “n”, “mpl.figure.prototype.handle_cursor = function (fig, msg) {n”, ” var cursor = msg[‘cursor’];n”, ” switch (cursor) {n”, ” case 0:n”, ” cursor = ‘pointer’;n”, ” break;n”, ” case 1:n”, ” cursor = ‘default’;n”, ” break;n”, ” case 2:n”, ” cursor = ‘crosshair’;n”, ” break;n”, ” case 3:n”, ” cursor = ‘move’;n”, ” break;n”, ” }n”, ” fig.rubberband_canvas.style.cursor = cursor;n”, “};n”, “n”, “mpl.figure.prototype.handle_message = function (fig, msg) {n”, ” fig.message.textContent = msg[‘message’];n”, “};n”, “n”, “mpl.figure.prototype.handle_draw = function (fig, _msg) {n”, ” // Request the server to send over a new figure.n”, ” fig.send_draw_message();n”, “};n”, “n”, “mpl.figure.prototype.handle_image_mode = function (fig, msg) {n”, ” fig.image_mode = msg[‘mode’];n”, “};n”, “n”, “mpl.figure.prototype.handle_history_buttons = function (fig, msg) {n”, ” for (var key in msg) {n”, ” if (!(key in fig.buttons)) {n”, ” continue;n”, ” }n”, ” fig.buttons[key].disabled = !msg[key];n”, ” fig.buttons[key].setAttribute(‘aria-disabled’, !msg[key]);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {n”, ” if (msg[‘mode’] === ‘PAN’) {n”, ” fig.buttons[‘Pan’].classList.add(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” } else if (msg[‘mode’] === ‘ZOOM’) {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.add(‘active’);n”, ” } else {n”, ” fig.buttons[‘Pan’].classList.remove(‘active’);n”, ” fig.buttons[‘Zoom’].classList.remove(‘active’);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Called whenever the canvas gets updated.n”, ” this.send_message(‘ack’, {});n”, “};n”, “n”, “// A function to construct a web socket function for onmessage handling.n”, “// Called in the figure constructor.n”, “mpl.figure.prototype._make_on_message_function = function (fig) {n”, ” return function socket_on_message(evt) {n”, ” if (evt.data instanceof Blob) {n”, ” / FIXME: We get "Resource interpreted as Image butn”, ” * transferred with MIME type text/plain:" errors onn”, ” * Chrome. But how to set the MIME type? It doesn’t seemn”, ” * to be part of the websocket stream /n”, ” evt.data.type = ‘image/png’;n”, “n”, ” / Free the memory for the previous frames /n”, ” if (fig.imageObj.src) {n”, ” (window.URL || window.webkitURL).revokeObjectURL(n”, ” fig.imageObj.srcn”, ” );n”, ” }n”, “n”, ” fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(n”, ” evt.datan”, ” );n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” } else if (n”, ” typeof evt.data === ‘string’ &&n”, ” evt.data.slice(0, 21) === ‘data:image/png;base64’n”, ” ) {n”, ” fig.imageObj.src = evt.data;n”, ” fig.updated_canvas_event();n”, ” fig.waiting = false;n”, ” return;n”, ” }n”, “n”, ” var msg = JSON.parse(evt.data);n”, ” var msg_type = msg[‘type’];n”, “n”, ” // Call the "handle_{type}" callback, which takesn”, ” // the figure and JSON message as its only arguments.n”, ” try {n”, ” var callback = fig[‘handle_’ + msg_type];n”, ” } catch (e) {n”, ” console.log(n”, ” "No handler for the ‘" + msg_type + "’ message type: ",n”, ” msgn”, ” );n”, ” return;n”, ” }n”, “n”, ” if (callback) {n”, ” try {n”, ” // console.log("Handling ‘" + msg_type + "’ message: ", msg);n”, ” callback(fig, msg);n”, ” } catch (e) {n”, ” console.log(n”, ” "Exception inside the ‘handler_" + msg_type + "’ callback:",n”, ” e,n”, ” e.stack,n”, ” msgn”, ” );n”, ” }n”, ” }n”, ” };n”, “};n”, “n”, “// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvasn”, “mpl.findpos = function (e) {n”, ” //this section is from http://www.quirksmode.org/js/events_properties.htmln”, ” var targ;n”, ” if (!e) {n”, ” e = window.event;n”, ” }n”, ” if (e.target) {n”, ” targ = e.target;n”, ” } else if (e.srcElement) {n”, ” targ = e.srcElement;n”, ” }n”, ” if (targ.nodeType === 3) {n”, ” // defeat Safari bugn”, ” targ = targ.parentNode;n”, ” }n”, “n”, ” // pageX,Y are the mouse positions relative to the documentn”, ” var boundingRect = targ.getBoundingClientRect();n”, ” var x = e.pageX - (boundingRect.left + document.body.scrollLeft);n”, ” var y = e.pageY - (boundingRect.top + document.body.scrollTop);n”, “n”, ” return { x: x, y: y };n”, “};n”, “n”, “/n”, ” * return a copy of an object with only non-object keysn”, ” * we need this to avoid circular referencesn”, ” * http://stackoverflow.com/a/24161582/3208463n”, ” /n”, “function simpleKeys(original) {n”, ” return Object.keys(original).reduce(function (obj, key) {n”, ” if (typeof original[key] !== ‘object’) {n”, ” obj[key] = original[key];n”, ” }n”, ” return obj;n”, ” }, {});n”, “}n”, “n”, “mpl.figure.prototype.mouse_event = function (event, name) {n”, ” var canvas_pos = mpl.findpos(event);n”, “n”, ” if (name === ‘button_press’) {n”, ” this.canvas.focus();n”, ” this.canvas_div.focus();n”, ” }n”, “n”, ” var x = canvas_pos.x * this.ratio;n”, ” var y = canvas_pos.y * this.ratio;n”, “n”, ” this.send_message(name, {n”, ” x: x,n”, ” y: y,n”, ” button: event.button,n”, ” step: event.step,n”, ” guiEvent: simpleKeys(event),n”, ” });n”, “n”, ” / This prevents the web browser from automatically changing ton”, ” * the text insertion cursor when the button is pressed. We wantn”, ” * to control all of the cursor setting manually through then”, ” * ‘cursor’ event from matplotlib */n”, ” event.preventDefault();n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (_event, _name) {n”, ” // Handle any extra behaviour associated with a key eventn”, “};n”, “n”, “mpl.figure.prototype.key_event = function (event, name) {n”, ” // Prevent repeat eventsn”, ” if (name === ‘key_press’) {n”, ” if (event.which === this._key) {n”, ” return;n”, ” } else {n”, ” this._key = event.which;n”, ” }n”, ” }n”, ” if (name === ‘key_release’) {n”, ” this._key = null;n”, ” }n”, “n”, ” var value = ‘’;n”, ” if (event.ctrlKey && event.which !== 17) {n”, ” value += ‘ctrl+’;n”, ” }n”, ” if (event.altKey && event.which !== 18) {n”, ” value += ‘alt+’;n”, ” }n”, ” if (event.shiftKey && event.which !== 16) {n”, ” value += ‘shift+’;n”, ” }n”, “n”, ” value += ‘k’;n”, ” value += event.which.toString();n”, “n”, ” this._key_event_extra(event, name);n”, “n”, ” this.send_message(name, { key: value, guiEvent: simpleKeys(event) });n”, ” return false;n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onclick = function (name) {n”, ” if (name === ‘download’) {n”, ” this.handle_save(this, null);n”, ” } else {n”, ” this.send_message(‘toolbar_button’, { name: name });n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {n”, ” this.message.textContent = tooltip;n”, “};n”,
- <<<<<<< HEAD
“n”, “///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////n”, “// prettier-ignoren”, “var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError("Constructor requires ‘new’ operator");i.set(this,e)}function h(){throw new TypeError("Function is not a constructor")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-linen”,
“n”, “mpl.extensions = ["eps", "jpeg", "pdf", "png", "ps", "raw", "svg", "tif"];n”, “n”, “mpl.default_extension = "png";/* global mpl */n”, “n”, “var comm_websocket_adapter = function (comm) {n”, ” // Create a "websocket"-like object which calls the given IPython commn”, ” // object with the appropriate methods. Currently this is a non binaryn”, ” // socket, so there is still some room for performance tuning.n”, ” var ws = {};n”, “n”, ” ws.close = function () {n”, ” comm.close();n”, ” };n”, ” ws.send = function (m) {n”, ” //console.log(‘sending’, m);n”, ” comm.send(m);n”, ” };n”, ” // Register the callback with on_msg.n”, ” comm.on_msg(function (msg) {n”, ” //console.log(‘receiving’, msg[‘content’][‘data’], msg);n”, ” // Pass the mpl event to the overridden (by mpl) onmessage function.n”, ” ws.onmessage(msg[‘content’][‘data’]);n”, ” });n”, ” return ws;n”, “};n”, “n”, “mpl.mpl_figure_comm = function (comm, msg) {n”, ” // This is the function which gets called when the mpl processn”, ” // starts-up an IPython Comm through the "matplotlib" channel.n”, “n”, ” var id = msg.content.data.id;n”, ” // Get hold of the div created by the display call when the Commn”, ” // socket was opened in Python.n”, ” var element = document.getElementById(id);n”, ” var ws_proxy = comm_websocket_adapter(comm);n”, “n”, ” function ondownload(figure, _format) {n”, ” window.open(figure.canvas.toDataURL());n”, ” }n”, “n”, ” var fig = new mpl.figure(id, ws_proxy, ondownload, element);n”, “n”, ” // Call onopen now - mpl needs it, as it is assuming we’ve passed it a realn”, ” // web socket which is closed, not our websocket->open comm proxy.n”, ” ws_proxy.onopen();n”, “n”, ” fig.parent_element = element;n”, ” fig.cell_info = mpl.find_output_cell("<div id=’" + id + "’></div>");n”, ” if (!fig.cell_info) {n”, ” console.error(‘Failed to find cell for figure’, id, fig);n”, ” return;n”, ” }n”,
- <<<<<<< HEAD
” fig.cell_info[0].output_area.element.on(n”,
” ‘cleared’,n”, ” { fig: fig },n”, ” fig._remove_fig_handlern”, ” );n”, “};n”, “n”, “mpl.figure.prototype.handle_close = function (fig, msg) {n”, ” var width = fig.canvas.width / fig.ratio;n”, ” fig.cell_info[0].output_area.element.off(n”, ” ‘cleared’,n”, ” fig._remove_fig_handlern”, ” );n”,
- <<<<<<< HEAD
” fig.resizeObserverInstance.unobserve(fig.canvas_div);n”,
” // Update the output cell to use the data from the current canvas.n”, ” fig.push_to_output();n”, ” var dataURL = fig.canvas.toDataURL();n”, ” // Re-enable the keyboard manager in IPython - without this line, in FF,n”, ” // the notebook keyboard shortcuts fail.n”, ” IPython.keyboard_manager.enable();n”, ” fig.parent_element.innerHTML =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, ” fig.close_ws(fig, msg);n”, “};n”, “n”, “mpl.figure.prototype.close_ws = function (fig, msg) {n”, ” fig.send_message(‘closing’, msg);n”, ” // fig.ws.close()n”, “};n”, “n”, “mpl.figure.prototype.push_to_output = function (_remove_interactive) {n”, ” // Turn the data on the canvas into data in the output cell.n”, ” var width = this.canvas.width / this.ratio;n”, ” var dataURL = this.canvas.toDataURL();n”, ” this.cell_info[1][‘text/html’] =n”, ” ‘<img src="’ + dataURL + ‘" width="’ + width + ‘">’;n”, “};n”, “n”, “mpl.figure.prototype.updated_canvas_event = function () {n”, ” // Tell IPython that the notebook contents must change.n”, ” IPython.notebook.set_dirty(true);n”, ” this.send_message(‘ack’, {});n”, ” var fig = this;n”, ” // Wait a second, then push the new image to the DOM son”, ” // that it is saved nicely (might be nice to debounce this).n”, ” setTimeout(function () {n”, ” fig.push_to_output();n”, ” }, 1000);n”, “};n”, “n”, “mpl.figure.prototype._init_toolbar = function () {n”, ” var fig = this;n”, “n”, ” var toolbar = document.createElement(‘div’);n”, ” toolbar.classList = ‘btn-toolbar’;n”, ” this.root.appendChild(toolbar);n”, “n”, ” function on_click_closure(name) {n”, ” return function (_event) {n”, ” return fig.toolbar_button_onclick(name);n”, ” };n”, ” }n”, “n”, ” function on_mouseover_closure(tooltip) {n”, ” return function (event) {n”, ” if (!event.currentTarget.disabled) {n”, ” return fig.toolbar_button_onmouseover(tooltip);n”, ” }n”, ” };n”, ” }n”, “n”, ” fig.buttons = {};n”, ” var buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” var button;n”, ” for (var toolbar_ind in mpl.toolbar_items) {n”, ” var name = mpl.toolbar_items[toolbar_ind][0];n”, ” var tooltip = mpl.toolbar_items[toolbar_ind][1];n”, ” var image = mpl.toolbar_items[toolbar_ind][2];n”, ” var method_name = mpl.toolbar_items[toolbar_ind][3];n”, “n”, ” if (!name) {n”, ” /* Instead of a spacer, we start a new button group. */n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, ” buttonGroup = document.createElement(‘div’);n”, ” buttonGroup.classList = ‘btn-group’;n”, ” continue;n”, ” }n”, “n”, ” button = fig.buttons[name] = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-default’;n”, ” button.href = ‘#’;n”, ” button.title = name;n”, ” button.innerHTML = ‘<i class="fa ‘ + image + ‘ fa-lg"></i>’;n”, ” button.addEventListener(‘click’, on_click_closure(method_name));n”, ” button.addEventListener(‘mouseover’, on_mouseover_closure(tooltip));n”, ” buttonGroup.appendChild(button);n”, ” }n”, “n”, ” if (buttonGroup.hasChildNodes()) {n”, ” toolbar.appendChild(buttonGroup);n”, ” }n”, “n”, ” // Add the status bar.n”, ” var status_bar = document.createElement(‘span’);n”, ” status_bar.classList = ‘mpl-message pull-right’;n”, ” toolbar.appendChild(status_bar);n”, ” this.message = status_bar;n”, “n”, ” // Add the close button to the window.n”, ” var buttongrp = document.createElement(‘div’);n”, ” buttongrp.classList = ‘btn-group inline pull-right’;n”, ” button = document.createElement(‘button’);n”, ” button.classList = ‘btn btn-mini btn-primary’;n”, ” button.href = ‘#’;n”, ” button.title = ‘Stop Interaction’;n”, ” button.innerHTML = ‘<i class="fa fa-power-off icon-remove icon-large"></i>’;n”, ” button.addEventListener(‘click’, function (_evt) {n”, ” fig.handle_close(fig, {});n”, ” });n”, ” button.addEventListener(n”, ” ‘mouseover’,n”, ” on_mouseover_closure(‘Stop Interaction’)n”, ” );n”, ” buttongrp.appendChild(button);n”, ” var titlebar = this.root.querySelector(‘.ui-dialog-titlebar’);n”, ” titlebar.insertBefore(buttongrp, titlebar.firstChild);n”, “};n”, “n”, “mpl.figure.prototype._remove_fig_handler = function (event) {n”, ” var fig = event.data.fig;n”,
- <<<<<<< HEAD
” if (event.target !== this) {n”, ” // Ignore bubbled events from children.n”, ” return;n”, ” }n”,
“};n”, “n”, “mpl.figure.prototype._root_extra_style = function (el) {n”, ” el.style.boxSizing = ‘content-box’; // override notebook setting of border-box.n”, “};n”, “n”, “mpl.figure.prototype._canvas_extra_style = function (el) {n”, ” // this is important to make the div ‘focusablen”, ” el.setAttribute(‘tabindex’, 0);n”, ” // reach out to IPython and tell the keyboard manager to turn it’s selfn”, ” // off when our div gets focusn”, “n”, ” // location in version 3n”, ” if (IPython.notebook.keyboard_manager) {n”, ” IPython.notebook.keyboard_manager.register_events(el);n”, ” } else {n”, ” // location in version 2n”, ” IPython.keyboard_manager.register_events(el);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype._key_event_extra = function (event, _name) {n”, ” var manager = IPython.notebook.keyboard_manager;n”, ” if (!manager) {n”, ” manager = IPython.keyboard_manager;n”, ” }n”, “n”, ” // Check for shift+entern”, ” if (event.shiftKey && event.which === 13) {n”, ” this.canvas_div.blur();n”, ” // select the cell after this onen”, ” var index = IPython.notebook.find_cell_index(this.cell_info[0]);n”, ” IPython.notebook.select(index + 1);n”, ” }n”, “};n”, “n”, “mpl.figure.prototype.handle_save = function (fig, _msg) {n”, ” fig.ondownload(fig, null);n”, “};n”, “n”, “mpl.find_output_cell = function (html_output) {n”, ” // Return the cell and output element which can be found uniquely in the notebook.n”, ” // Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"n”, ” // IPython event is triggered only after the cells have been serialised, which forn”, ” // our purposes (turning an active figure into a static one), is too late.n”, ” var cells = IPython.notebook.get_cells();n”, ” var ncells = cells.length;n”, ” for (var i = 0; i < ncells; i++) {n”, ” var cell = cells[i];n”, ” if (cell.cell_type === ‘code’) {n”, ” for (var j = 0; j < cell.output_area.outputs.length; j++) {n”, ” var data = cell.output_area.outputs[j];n”, ” if (data.data) {n”, ” // IPython >= 3 moved mimebundle to data attribute of outputn”, ” data = data.data;n”, ” }n”, ” if (data[‘text/html’] === html_output) {n”, ” return [cell, data, j];n”, ” }n”, ” }n”, ” }n”, ” }n”, “};n”, “n”, “// Register the function which deals with the matplotlib target/channel.n”, “// The kernel may be null if the page has been refreshed.n”, “if (IPython.notebook.kernel !== null) {n”, ” IPython.notebook.kernel.comm_manager.register_target(n”, ” ‘matplotlib’,n”, ” mpl.mpl_figure_commn”, ” );n”, “}n”
], “text/plain”: [
“<IPython.core.display.Javascript object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}, {
- “data”: {
“text/html”: [
], “text/plain”: [
“<IPython.core.display.HTML object>”
]
}, “metadata”: {}, “output_type”: “display_data”
}
], “source”: [
“from matplotlib import patchesn”, “fig = plt.figure(figsize=(9, 6)) n”, “n”, “extent= np.array([-center[0], diff_pattern.shape[0]-center[0],-diff_pattern.shape[1]+center[1], center[1]])*scalen”, “n”, “plt.imshow(np.log2(1+diff_pattern).T,cmap="gray", extent=(extent), vmin=np.max(np.log2(1+diff_pattern))*0.5)n”, “plt.xlabel(r’reciprocal distance [nm$^{-1}$]’)n”, “ax = fig.gca()n”, “#ax.add_artist(circle1);n”, “plt.plot(np.linspace(1,len(profile),len(profile))*scale,profile/profile.max()*10, color=’y’);n”, “plt.plot((0,len(profile)*scale),(0,0),c=’r’)n”, “n”, “for j in range(len(unique)-1):n”, ” i = indices[j] n”, ” if distances[i] < len(profile)*scale:n”, ” plt.plot([distances[i],distances[i]], [0, intensity2[j]/20],c=’r’)n”, ” arc = patches.Arc((0,0), distances[i]*2, distances[i]*2, angle=90.0, theta1=0.0, theta2=270.0, color=’r’, fill= False, alpha = 0.5)#, **kwargs)n”, ” ax.add_artist(arc);n”, “plt.scatter(0,0);n”, “n”, “for i in range(6):n”, ” index = ‘{‘+f’{family[i][0]:.0f} {family[i][1]:.0f} {family[i][2]:.0f}’+’}’ # pretty index stringn”, ” plt.text(unique[i],-0.5, index, horizontalalignment=’center’,n”, ” verticalalignment=’top’, rotation = ‘vertical’, fontsize=8, color = ‘white’)”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“### Quizn”, “What would the figure caption for above figure be?”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“### What does the above figure convey?n”, “n”, “* center is determined accuratelyn”, “* relative distances are accurately describedn”, “* scaling accurately for reference crystal - calibration?n”, “n”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“### What is the accuracy?n”, “n”, “Change the scale by 1% and see what happensn”, “n”, “So we can determine the lattce parameter better than 1% if we use high scattering angles!n”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Logging the resultsn”
]
}, {
“cell_type”: “code”,
- <<<<<<< HEAD
“execution_count”: 15,
“metadata”: {}, “outputs”: [
- {
“name”: “stdout”, “output_type”: “stream”, “text”: [
“/n”, “├ Measurement_000n”, ” —————n”, ” ├ Channel_000n”, ” ———–n”, ” ├ GOLD_NP_DIFFn”, ” ————n”, ” ├ GOLD_NP_DIFFn”, ” ├ __dict__n”, ” ——–n”, ” ├ _axesn”, ” —–n”, ” ├ _original_metadatan”, ” ——————n”, ” ├ original_metadatan”, ” —————–n”, ” ├ un”, ” ├ vn”, ” ├ Log_000n”, ” ——-n”, ” ├ analysisn”, ” ├ centern”, ” ├ polar_projectionn”, ” ├ radial_averagen”, ” ├ reflections-0-indexn”, ” ├ reflections-0-intensityn”, ” ├ reflections-0-multiplicityn”, ” ├ reflections-0-recip_distancesn”, ” ├ reflections-0-structure_factorn”, ” ├ reflections-1-indexn”, ” ├ reflections-1-intensityn”, ” ├ reflections-1-multiplicityn”, ” ├ reflections-1-recip_distancesn”, ” ├ reflections-1-structure_factorn”, ” ├ reflections-10-indexn”, ” ├ reflections-10-intensityn”, ” ├ reflections-10-multiplicityn”, ” ├ reflections-10-recip_distancesn”, ” ├ reflections-10-structure_factorn”, ” ├ reflections-11-indexn”, ” ├ reflections-11-intensityn”, ” ├ reflections-11-multiplicityn”, ” ├ reflections-11-recip_distancesn”, ” ├ reflections-11-structure_factorn”, ” ├ reflections-12-indexn”, ” ├ reflections-12-intensityn”, ” ├ reflections-12-multiplicityn”, ” ├ reflections-12-recip_distancesn”, ” ├ reflections-12-structure_factorn”, ” ├ reflections-13-indexn”, ” ├ reflections-13-intensityn”, ” ├ reflections-13-multiplicityn”, ” ├ reflections-13-recip_distancesn”, ” ├ reflections-13-structure_factorn”, ” ├ reflections-14-indexn”, ” ├ reflections-14-intensityn”, ” ├ reflections-14-multiplicityn”, ” ├ reflections-14-recip_distancesn”, ” ├ reflections-14-structure_factorn”, ” ├ reflections-15-indexn”, ” ├ reflections-15-intensityn”, ” ├ reflections-15-multiplicityn”, ” ├ reflections-15-recip_distancesn”, ” ├ reflections-15-structure_factorn”, ” ├ reflections-16-indexn”, ” ├ reflections-16-intensityn”, ” ├ reflections-16-multiplicityn”, ” ├ reflections-16-recip_distancesn”, ” ├ reflections-16-structure_factorn”, ” ├ reflections-17-indexn”, ” ├ reflections-17-intensityn”, ” ├ reflections-17-multiplicityn”, ” ├ reflections-17-recip_distancesn”, ” ├ reflections-17-structure_factorn”, ” ├ reflections-18-indexn”, ” ├ reflections-18-intensityn”, ” ├ reflections-18-multiplicityn”, ” ├ reflections-18-recip_distancesn”, ” ├ reflections-18-structure_factorn”, ” ├ reflections-19-indexn”, ” ├ reflections-19-intensityn”, ” ├ reflections-19-multiplicityn”, ” ├ reflections-19-recip_distancesn”, ” ├ reflections-19-structure_factorn”, ” ├ reflections-2-indexn”, ” ├ reflections-2-intensityn”, ” ├ reflections-2-multiplicityn”, ” ├ reflections-2-recip_distancesn”, ” ├ reflections-2-structure_factorn”, ” ├ reflections-20-indexn”, ” ├ reflections-20-intensityn”, ” ├ reflections-20-multiplicityn”, ” ├ reflections-20-recip_distancesn”, ” ├ reflections-20-structure_factorn”, ” ├ reflections-21-indexn”, ” ├ reflections-21-intensityn”, ” ├ reflections-21-multiplicityn”, ” ├ reflections-21-recip_distancesn”, ” ├ reflections-21-structure_factorn”, ” ├ reflections-22-indexn”, ” ├ reflections-22-intensityn”, ” ├ reflections-22-multiplicityn”, ” ├ reflections-22-recip_distancesn”, ” ├ reflections-22-structure_factorn”, ” ├ reflections-23-indexn”, ” ├ reflections-23-intensityn”, ” ├ reflections-23-multiplicityn”, ” ├ reflections-23-recip_distancesn”, ” ├ reflections-23-structure_factorn”, ” ├ reflections-24-indexn”, ” ├ reflections-24-intensityn”, ” ├ reflections-24-multiplicityn”, ” ├ reflections-24-recip_distancesn”, ” ├ reflections-24-structure_factorn”, ” ├ reflections-25-indexn”, ” ├ reflections-25-intensityn”, ” ├ reflections-25-multiplicityn”, ” ├ reflections-25-recip_distancesn”, ” ├ reflections-25-structure_factorn”, ” ├ reflections-26-indexn”, ” ├ reflections-26-intensityn”, ” ├ reflections-26-multiplicityn”, ” ├ reflections-26-recip_distancesn”, ” ├ reflections-26-structure_factorn”, ” ├ reflections-27-indexn”, ” ├ reflections-27-intensityn”, ” ├ reflections-27-multiplicityn”, ” ├ reflections-27-recip_distancesn”, ” ├ reflections-27-structure_factorn”, ” ├ reflections-28-indexn”, ” ├ reflections-28-intensityn”, ” ├ reflections-28-multiplicityn”, ” ├ reflections-28-recip_distancesn”, ” ├ reflections-28-structure_factorn”, ” ├ reflections-29-indexn”, ” ├ reflections-29-intensityn”, ” ├ reflections-29-multiplicityn”, ” ├ reflections-29-recip_distancesn”, ” ├ reflections-29-structure_factorn”, ” ├ reflections-3-indexn”, ” ├ reflections-3-intensityn”, ” ├ reflections-3-multiplicityn”, ” ├ reflections-3-recip_distancesn”, ” ├ reflections-3-structure_factorn”, ” ├ reflections-30-indexn”, ” ├ reflections-30-intensityn”, ” ├ reflections-30-multiplicityn”, ” ├ reflections-30-recip_distancesn”, ” ├ reflections-30-structure_factorn”, ” ├ reflections-31-indexn”, ” ├ reflections-31-intensityn”, ” ├ reflections-31-multiplicityn”, ” ├ reflections-31-recip_distancesn”, ” ├ reflections-31-structure_factorn”, ” ├ reflections-32-indexn”, ” ├ reflections-32-intensityn”, ” ├ reflections-32-multiplicityn”, ” ├ reflections-32-recip_distancesn”, ” ├ reflections-32-structure_factorn”, ” ├ reflections-33-indexn”, ” ├ reflections-33-intensityn”, ” ├ reflections-33-multiplicityn”, ” ├ reflections-33-recip_distancesn”, ” ├ reflections-33-structure_factorn”, ” ├ reflections-34-indexn”, ” ├ reflections-34-intensityn”, ” ├ reflections-34-multiplicityn”, ” ├ reflections-34-recip_distancesn”, ” ├ reflections-34-structure_factorn”, ” ├ reflections-35-indexn”, ” ├ reflections-35-intensityn”, ” ├ reflections-35-multiplicityn”, ” ├ reflections-35-recip_distancesn”, ” ├ reflections-35-structure_factorn”, ” ├ reflections-36-indexn”, ” ├ reflections-36-intensityn”, ” ├ reflections-36-multiplicityn”, ” ├ reflections-36-recip_distancesn”, ” ├ reflections-36-structure_factorn”, ” ├ reflections-4-indexn”, ” ├ reflections-4-intensityn”, ” ├ reflections-4-multiplicityn”, ” ├ reflections-4-recip_distancesn”, ” ├ reflections-4-structure_factorn”, ” ├ reflections-5-indexn”, ” ├ reflections-5-intensityn”, ” ├ reflections-5-multiplicityn”, ” ├ reflections-5-recip_distancesn”, ” ├ reflections-5-structure_factorn”, ” ├ reflections-6-indexn”, ” ├ reflections-6-intensityn”, ” ├ reflections-6-multiplicityn”, ” ├ reflections-6-recip_distancesn”, ” ├ reflections-6-structure_factorn”, ” ├ reflections-7-indexn”, ” ├ reflections-7-intensityn”, ” ├ reflections-7-multiplicityn”, ” ├ reflections-7-recip_distancesn”, ” ├ reflections-7-structure_factorn”, ” ├ reflections-8-indexn”, ” ├ reflections-8-intensityn”, ” ├ reflections-8-multiplicityn”, ” ├ reflections-8-recip_distancesn”, ” ├ reflections-8-structure_factorn”, ” ├ reflections-9-indexn”, ” ├ reflections-9-intensityn”, ” ├ reflections-9-multiplicityn”, ” ├ reflections-9-recip_distancesn”, ” ├ reflections-9-structure_factorn”, ” ├ ring_radii_pxn”, ” ├ scalen”,
- <<<<<<< HEAD
” ├ Log_001n”, ” ——-n”, ” ├ analysisn”, ” ├ centern”, ” ├ polar_projectionn”, ” ├ radial_averagen”, ” ├ reflections-0-indexn”, ” ├ reflections-0-intensityn”, ” ├ reflections-0-multiplicityn”, ” ├ reflections-0-recip_distancesn”, ” ├ reflections-0-structure_factorn”, ” ├ reflections-1-indexn”, ” ├ reflections-1-intensityn”, ” ├ reflections-1-multiplicityn”, ” ├ reflections-1-recip_distancesn”, ” ├ reflections-1-structure_factorn”, ” ├ reflections-10-indexn”, ” ├ reflections-10-intensityn”, ” ├ reflections-10-multiplicityn”, ” ├ reflections-10-recip_distancesn”, ” ├ reflections-10-structure_factorn”, ” ├ reflections-11-indexn”, ” ├ reflections-11-intensityn”, ” ├ reflections-11-multiplicityn”, ” ├ reflections-11-recip_distancesn”, ” ├ reflections-11-structure_factorn”, ” ├ reflections-12-indexn”, ” ├ reflections-12-intensityn”, ” ├ reflections-12-multiplicityn”, ” ├ reflections-12-recip_distancesn”, ” ├ reflections-12-structure_factorn”, ” ├ reflections-13-indexn”, ” ├ reflections-13-intensityn”, ” ├ reflections-13-multiplicityn”, ” ├ reflections-13-recip_distancesn”, ” ├ reflections-13-structure_factorn”, ” ├ reflections-14-indexn”, ” ├ reflections-14-intensityn”, ” ├ reflections-14-multiplicityn”, ” ├ reflections-14-recip_distancesn”, ” ├ reflections-14-structure_factorn”, ” ├ reflections-15-indexn”, ” ├ reflections-15-intensityn”, ” ├ reflections-15-multiplicityn”, ” ├ reflections-15-recip_distancesn”, ” ├ reflections-15-structure_factorn”, ” ├ reflections-16-indexn”, ” ├ reflections-16-intensityn”, ” ├ reflections-16-multiplicityn”, ” ├ reflections-16-recip_distancesn”, ” ├ reflections-16-structure_factorn”, ” ├ reflections-17-indexn”, ” ├ reflections-17-intensityn”, ” ├ reflections-17-multiplicityn”, ” ├ reflections-17-recip_distancesn”, ” ├ reflections-17-structure_factorn”, ” ├ reflections-18-indexn”, ” ├ reflections-18-intensityn”, ” ├ reflections-18-multiplicityn”, ” ├ reflections-18-recip_distancesn”, ” ├ reflections-18-structure_factorn”, ” ├ reflections-19-indexn”, ” ├ reflections-19-intensityn”, ” ├ reflections-19-multiplicityn”, ” ├ reflections-19-recip_distancesn”, ” ├ reflections-19-structure_factorn”, ” ├ reflections-2-indexn”, ” ├ reflections-2-intensityn”, ” ├ reflections-2-multiplicityn”, ” ├ reflections-2-recip_distancesn”, ” ├ reflections-2-structure_factorn”, ” ├ reflections-20-indexn”, ” ├ reflections-20-intensityn”, ” ├ reflections-20-multiplicityn”, ” ├ reflections-20-recip_distancesn”, ” ├ reflections-20-structure_factorn”, ” ├ reflections-21-indexn”, ” ├ reflections-21-intensityn”, ” ├ reflections-21-multiplicityn”, ” ├ reflections-21-recip_distancesn”, ” ├ reflections-21-structure_factorn”, ” ├ reflections-22-indexn”, ” ├ reflections-22-intensityn”, ” ├ reflections-22-multiplicityn”, ” ├ reflections-22-recip_distancesn”, ” ├ reflections-22-structure_factorn”, ” ├ reflections-23-indexn”, ” ├ reflections-23-intensityn”, ” ├ reflections-23-multiplicityn”, ” ├ reflections-23-recip_distancesn”, ” ├ reflections-23-structure_factorn”, ” ├ reflections-24-indexn”, ” ├ reflections-24-intensityn”, ” ├ reflections-24-multiplicityn”, ” ├ reflections-24-recip_distancesn”, ” ├ reflections-24-structure_factorn”, ” ├ reflections-25-indexn”, ” ├ reflections-25-intensityn”, ” ├ reflections-25-multiplicityn”, ” ├ reflections-25-recip_distancesn”, ” ├ reflections-25-structure_factorn”, ” ├ reflections-26-indexn”, ” ├ reflections-26-intensityn”, ” ├ reflections-26-multiplicityn”, ” ├ reflections-26-recip_distancesn”, ” ├ reflections-26-structure_factorn”, ” ├ reflections-27-indexn”, ” ├ reflections-27-intensityn”, ” ├ reflections-27-multiplicityn”, ” ├ reflections-27-recip_distancesn”, ” ├ reflections-27-structure_factorn”, ” ├ reflections-28-indexn”, ” ├ reflections-28-intensityn”, ” ├ reflections-28-multiplicityn”, ” ├ reflections-28-recip_distancesn”, ” ├ reflections-28-structure_factorn”, ” ├ reflections-29-indexn”, ” ├ reflections-29-intensityn”, ” ├ reflections-29-multiplicityn”, ” ├ reflections-29-recip_distancesn”, ” ├ reflections-29-structure_factorn”, ” ├ reflections-3-indexn”, ” ├ reflections-3-intensityn”, ” ├ reflections-3-multiplicityn”, ” ├ reflections-3-recip_distancesn”, ” ├ reflections-3-structure_factorn”, ” ├ reflections-30-indexn”, ” ├ reflections-30-intensityn”, ” ├ reflections-30-multiplicityn”, ” ├ reflections-30-recip_distancesn”, ” ├ reflections-30-structure_factorn”, ” ├ reflections-31-indexn”, ” ├ reflections-31-intensityn”, ” ├ reflections-31-multiplicityn”, ” ├ reflections-31-recip_distancesn”, ” ├ reflections-31-structure_factorn”, ” ├ reflections-32-indexn”, ” ├ reflections-32-intensityn”, ” ├ reflections-32-multiplicityn”, ” ├ reflections-32-recip_distancesn”, ” ├ reflections-32-structure_factorn”, ” ├ reflections-33-indexn”, ” ├ reflections-33-intensityn”, ” ├ reflections-33-multiplicityn”, ” ├ reflections-33-recip_distancesn”, ” ├ reflections-33-structure_factorn”, ” ├ reflections-34-indexn”, ” ├ reflections-34-intensityn”, ” ├ reflections-34-multiplicityn”, ” ├ reflections-34-recip_distancesn”, ” ├ reflections-34-structure_factorn”, ” ├ reflections-35-indexn”, ” ├ reflections-35-intensityn”, ” ├ reflections-35-multiplicityn”, ” ├ reflections-35-recip_distancesn”, ” ├ reflections-35-structure_factorn”, ” ├ reflections-36-indexn”, ” ├ reflections-36-intensityn”, ” ├ reflections-36-multiplicityn”, ” ├ reflections-36-recip_distancesn”, ” ├ reflections-36-structure_factorn”, ” ├ reflections-4-indexn”, ” ├ reflections-4-intensityn”, ” ├ reflections-4-multiplicityn”, ” ├ reflections-4-recip_distancesn”, ” ├ reflections-4-structure_factorn”, ” ├ reflections-5-indexn”, ” ├ reflections-5-intensityn”, ” ├ reflections-5-multiplicityn”, ” ├ reflections-5-recip_distancesn”, ” ├ reflections-5-structure_factorn”, ” ├ reflections-6-indexn”, ” ├ reflections-6-intensityn”, ” ├ reflections-6-multiplicityn”, ” ├ reflections-6-recip_distancesn”, ” ├ reflections-6-structure_factorn”, ” ├ reflections-7-indexn”, ” ├ reflections-7-intensityn”, ” ├ reflections-7-multiplicityn”, ” ├ reflections-7-recip_distancesn”, ” ├ reflections-7-structure_factorn”, ” ├ reflections-8-indexn”, ” ├ reflections-8-intensityn”, ” ├ reflections-8-multiplicityn”, ” ├ reflections-8-recip_distancesn”, ” ├ reflections-8-structure_factorn”, ” ├ reflections-9-indexn”, ” ├ reflections-9-intensityn”, ” ├ reflections-9-multiplicityn”, ” ├ reflections-9-recip_distancesn”, ” ├ reflections-9-structure_factorn”, ” ├ ring_radii_pxn”, ” ├ scalen”,
” ————-n”, ” ├ _goldn”, ” ├ elementsn”, ” ├ relative_positionsn”, ” ├ titlen”, ” ├ unit_celln”,
<<<<<<< HEAD¶
” ├ zone_axisn”, “├ Structure_001n”, ” ————-n”, ” ├ _goldn”, ” ├ elementsn”, ” ├ relative_positionsn”, ” ├ titlen”, ” ├ unit_celln”,
- >>>>>>> d27eb02fc99b5249297c72b2b388a2377fbe501e
” ├ zone_axisn”
]
}
], “source”: [
“out_tags[‘analysis’] = ‘Indexing_Diffraction_Rings’n”, “out_tags[‘scale’] = scalen”, “log_group = ft.log_results(main_dataset, dataset=None, attributes=out_tags)n”, “n”, “current_filename = log_group.file.filenamen”, “ft.h5_tree(main_dataset)n”, “main_dataset.h5_dataset.file.close()”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Conclusionn”, “n”, “We only need the scatterng factors to calculate the ring pattern.n”, “n”, “A comparison between simulation and experiment can be very precise.n”, “n”, “Normally one would do a fit of the most prominent peaks to establish the scale. “
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Navigationn”, “n”, “- <font size = "3"> Back Chapter 1: [Atomic Form Factor](CH2_04-Basic_Crystallography.ipynb) </font>n”, “- <font size = "3"> Next: [Structure Factors](CH2_06-Kinematic_Scattering_Geometry.ipynb) </font>n”, “- <font size = "3"> Chapter 2: [Diffraction](CH2_00-Diffraction.ipynb) </font>n”, “- <font size = "3"> List of Content: [Front](../_MSE672_Intro_TEM.ipynb) </font>n”, “n”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Appendixn”, ” Opening the hdf5 file and plot the data againn”, “n”, “### Open hf5 filen”
]
}, {
“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [
“new_dataset = ft.open_file(current_filename)n”, “n”, “new_dataset.plot()”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“### And Plotn”, “n”, “Becasue we saved all the results in all steps, it is straight forward to retrieve the publication quality plot again.”
]
}, {
“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [
“## Access the data of the loaded imagen”, “n”, “n”, “diff_pattern = new_datasetn”, “diff_pattern = diff_pattern-diff_pattern.min()n”, “current_channel = new_dataset.h5_dataset.parent.parentn”, “result_group = current_channel[‘Log_000’]n”, “n”, “center = result_group[‘center’][()]n”, “scale = result_group[‘scale’][()]n”, “n”, “from matplotlib import patchesn”, “fig = plt.figure(figsize=(9, 6)) n”, “ax = plt.gca()n”, “extent= np.array([-center[0], diff_pattern.shape[0]-center[0],-diff_pattern.shape[1]+center[1], center[1]])*scalen”, “n”, “plt.imshow(np.log2(1+diff_pattern).T, cmap="gray", extent=(extent), vmin=np.max(np.log2(1+diff_pattern))*0.5)n”, “plt.xlabel(r’reciprocal distance [nm$^{-1}$]’)n”, “n”, “profile = result_group[‘radial_average’][()]n”, “plt.plot(np.linspace(1,len(profile),len(profile))*scale,profile/profile.max()*10, color=’y’);#n”, “plt.plot((0,len(profile)*scale),(0,0),c=’r’)n”, “reflections = {}n”, “for key in result_group:n”, ” if ‘reflection’ in key:n”, ” keys = key.split(‘-‘)n”, ” n”, ” if keys[1] not in reflections:n”, ” reflections[keys[1]]={}n”, ” reflections[keys[1]][keys[2]] = result_group[key][()]n”, ” #print( reflections[keys[1]][keys[2]] )n”, “for key in reflections:n”, ” distance = reflections[key][‘recip_distances’]n”, ” if distance < len(profile)*scale:n”, ” n”, ” plt.plot([distance,distance], [0, reflections[key][‘intensity’]/1000],c=’r’)n”, ” arc = patches.Arc((0,0), distance*2, distance*2, angle=90.0, theta1=0.0, theta2=270.0, color=’r’, fill= False, alpha = 0.5)#, **kwargs)n”, ” ax.add_artist(arc);n”, “plt.scatter(0,0);n”, “for i in range(7):n”, ” index = reflections[str(i)][‘index’] # pretty index stringn”, ” plt.text(unique[i],-0.5, index, horizontalalignment=’center’,n”, ” verticalalignment=’top’, rotation = ‘vertical’, fontsize=8, color = ‘white’)n”
]
}, {
“cell_type”: “markdown”, “metadata”: {}, “source”: [
“## Close Filen”
]
}, {
“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [
“new_dataset.h5_dataset.file.close()”
]
}, {
“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [
“import scipyn”, “import scipy.signaln”, “print((831 +1327) - 1024)n”, “print((803 +1288) - 1024)n”, “x_line_plot = diff_pattern[np.arange(2048),np.arange(2048)]n”, “y_line_plot = diff_pattern[np.arange(2048),2047-np.arange(2048)]n”, “peaks_x = scipy.signal.find_peaks(x_line_plot, prominence=5000)n”, “peaks_y = scipy.signal.find_peaks(y_line_plot, prominence=5000)n”, “print(peaks_x[0],peaks_y[0])n”, “plt.figure()n”, “#plt.plot(diff_pattern[:, 1022:1025].sum(axis=1))n”, “plt.plot(np.arange(2048)+-(1134-1067)/2, x_line_plot)n”, “plt.plot(y_line_plot)n”, “plt.scatter(peaks_x[0], x_line_plot[peaks_x[0]])n”, “plt.scatter(peaks_y[0], y_line_plot[peaks_y[0]])”
]
}
], “metadata”: {
“celltoolbar”: “Slideshow”, “kernelspec”: {
“display_name”: “Python 3”, “language”: “python”, “name”: “python3”
}, “language_info”: {
- “codemirror_mode”: {
“name”: “ipython”, “version”: 3
}, “file_extension”: “.py”, “mimetype”: “text/x-python”, “name”: “python”, “nbconvert_exporter”: “python”, “pygments_lexer”: “ipython3”, “version”: “3.8.5”
}, “livereveal”: {
“height”: 768, “theme”: “sky”, “transition”: “zoom”, “width”: 1024
}, “toc”: {
“base_numbering”: “5”, “nav_menu”: {}, “number_sections”: true, “sideBar”: true, “skip_h1_title”: false, “title_cell”: “Table of Contents”, “title_sidebar”: “Contents”, “toc_cell”: false, “toc_position”: {}, “toc_section_display”: true, “toc_window_display”: true
}
}, “nbformat”: 4, “nbformat_minor”: 4
}